numerical values assignment to symbolic variables

3 ビュー (過去 30 日間)
Ajinkya
Ajinkya 2024 年 9 月 18 日
回答済み: Sameer 2024 年 9 月 18 日
I have defined the following symbols
syms V1 V2 V3 V4 V5 V6 V7 V8 V9
I want to assign numerical values to them. How could I do it ?
  1 件のコメント
Stephen23
Stephen23 2024 年 9 月 18 日
V1 = sym(3)
class(V1)
ans = 'sym'
V1(1) = 2
class(V1)
ans = 'sym'

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

採用された回答

Sameer
Sameer 2024 年 9 月 18 日
Hi Ajinkya
To assign numerical values to "symbolic variables", you can use the "subs" function
Here's how you can do it:
syms V1 V2 V3 V4 V5 V6 V7 V8 V9
% Define the numerical values
values = [10, 20, 30, 40, 50, 60, 70, 80, 90];
% Substitute the values into the symbolic variables
V_values = subs([V1, V2, V3, V4, V5, V6, V7, V8, V9], [V1, V2, V3, V4, V5, V6, V7, V8, V9], values);
% Display the results
disp(V_values);
Direct Assignment in an Expression
If you are using these variables within an expression, you can substitute them directly:
syms V1 V2 V3 V4 V5 V6 V7 V8 V9
% Example expression
expression = V1 + V2 + V3;
% Substitute values
result = subs(expression, [V1, V2, V3], [10, 20, 30]);
% Display the result
disp(result);
Please refer to the below MathWorks documentation link:
Hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Variables, Expressions, Functions, and Preferences についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by