Calculating a new variable from a symbolic equation

조회 수: 1 (최근 30일)
Helena Hjørringgaard
Helena Hjørringgaard 2020년 3월 24일
댓글: Helena Hjørringgaard 2020년 3월 24일
I'm new to Matlab so I hope you can help me :-). I'm using MATLAB r2019a.
I have a array (Q) that I would like to use as a input in a equation and solve for a variable (y). I need the equation to calculate a y for each Q. How do I do that?
So far I've tried this (simplyfied):
Q_full = 0.5
Q = [1,2,3]
syms Q Q_full y
eqn = vpasolve(Q/Q_full == 2+y,y)
The errors I get are:
Error using mupadengine/feval (line 195)
Symbolic parameters not supported in nonpolynomial equations.
Error in sym/vpasolve (line 172)
sol = eng.feval('symobj::vpasolve',eqns,vars,X0);
Error in Model (line 30)
eqn = vpasolve(Q/Q_full == 0.46-(0.5*cos(pi*(y/D)))+(0.04*cos(2*pi*(y/D))),y); <- this is my real equation

채택된 답변

Birdman
Birdman 2020년 3월 24일
편집: Birdman 2020년 3월 24일
You already defined values for Q_full and Q. You do not need to define them as symbolic variables later. This will not work. Try the following approach:
Q_full = 0.5
Q = [1,2,3]
syms y
for i=1:numel(Q)
eqn(i) = vpasolve(Q(i)/Q_full == 2+y,y)
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 3월 24일
syms Q Q_full y
That line overwrites the numeric values that you assigned to Q and Q_full. That gives you an equation with more than one unresolved variable. vpasolve can only handle multiple unresolved variables for polynomials.
Do not do the syms on Q Q_full.
In any one call to vpasolve, vpasolve will attempt to find parameter values that satisfy all of the equations simultaneously. It never treats the inputs as a sequence of separate equations, only ever as simultaneous equations.
Therefore, either loop or else arrayfun
arrayfun(@(Qr) vpasolve(Qr == etc, y), Q./Q_full)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by