Symbolic equation with numeric variable

1 回表示 (過去 30 日間)
Rashmil Dahanayake
Rashmil Dahanayake 2013 年 9 月 23 日
Is it possible to use a numeric variable(in this case "alfa") in a symbolic equation.
I'm trying to solve the symbolic q. I need the flexibility to change the value of alfa. However if i use the term "alfa" when defining the eqn, marlab fails to solve the equation.
If I manually type the value of alfa inside the equation, the programs runs without a problem.
f=50;
w=2*pi*f;
R=303.47/50;
alfa=72;
syms q;
eqn = 'sin(72*pi/180) == cos(q) * exp(tan(q) * (pi/6 - 72*pi/180 + q))';
% This is the format I want to use,but gives errors
%----------------------------------------------------------------------
%eqn = 'sin(alfa*pi/180) == cos(q) * exp(tan(q) * (pi/6 - alfa*pi/180 + q))';
%----------------------------------------------------------------------
y= double(solve(eqn));
C=1/(w*R*tan(y)) /10^(-6) % Capacitor Value
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 23 日
What is the error message?

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

採用された回答

Walter Roberson
Walter Roberson 2013 年 9 月 23 日
編集済み: Walter Roberson 2013 年 9 月 23 日
eqn = subs('sin(alfa*pi/180) = cos(q) * exp(tan(q) * (pi/6 - alfa*pi/180 + q))', 'alfa', alfa);

その他の回答 (1 件)

Rashmil Dahanayake
Rashmil Dahanayake 2013 年 9 月 24 日
編集済み: Azzi Abdelmalek 2013 年 9 月 24 日
Subs method worked.
Alternatively you can define the eqn without quotation (') marks.
Therefore following code is also correct.
eqn = sin(alfa*pi/180) == cos(q) * exp(tan(q) * (pi/6 - alfa*pi/180 + q));
y= double(solve(eqn));
I'm wondering for symbolic solver is there any benefit passing arguments as a string.(ie using quotation marks)
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 9 月 24 日
When you pass as a string, you need to use MuPAD syntax. But in turn that means you can access MuPAD syntax and operators that do not have a direct MATLAB interface.
Or so the theory goes; I have not had my hands on a MuPAD version to experiment with.

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

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by