Filter löschen
Filter löschen

Define a symbolic variable and then calculate it later

2 Ansichten (letzte 30 Tage)
Alessandro Longo
Alessandro Longo am 7 Dez. 2017
Kommentiert: Stephen23 am 7 Dez. 2017
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 Kommentar
Stephen23
Stephen23 am 7 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by