Define a symbolic variable and then calculate it later
5 views (last 30 days)
Show older comments
Hello forum, I would build something like this:
my_input = 2+0.5*t;
with variable t not already defined. Then, in the same code, I would define the t vector and then re-calculate my_input with the proper values of t. I need it because in this code, the user can only modify the first section. If I declare the time variable earlier, there is the risk to be modified.
Example of what I would realize (but with syms it does not work):
syms t
my_input = 2+0.5*t; % t is a sort of symbolic variable
t = linspace(0,100,1000); % now t is a real variable
my_new_input = my_input; % but now calculated with real t values
1 Comment
Stephen23
on 7 Dec 2017
"I need it because in this code, the user can only modify the first section. If I declare the time variable earlier, there is the risk to be modified."
That is not a very good reason to use symbolic math. Just design your code better by splitting it into some functions that are called by the user.
Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!