Define a symbolic variable and then calculate it later

1 回表示 (過去 30 日間)
Alessandro Longo
Alessandro Longo 2017 年 12 月 7 日
コメント済み: Stephen23 2017 年 12 月 7 日
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 件のコメント
Stephen23
Stephen23 2017 年 12 月 7 日
"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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by