Trying to get the solve command to work
显示 更早的评论
[EDIT: 20110610 10:37 CDT - reformat - WDR]
I have a complex equation in which I am trying to solve for "P" in terms of all the other variables. All the other values will be known yet they are different for each application and the solved equation will be needed to go into excel. Some might be asking why don't I just input the known values into MATLAB each time and then solve for the single variable P. Well not everyone knows how to use MATLAB or has access and other people need to use it in the excel spreadsheet form. So anyways here is my code and I will show the errors. Any input would be greatly appreciated!
clear all
clc
syms A G P N B V O;
solve('A*G*sqrt((1-(P/G)^2)/(N-log(P/G))) = B*P*sqrt((1-(V/P)^2)/(O-log(V/P)))', 'P')
??? Error using ==> solve>getEqns at 182
' A*G*sqrt((1-(P/G)^2)/(N-log(P/G))) = B*P*sqrt((1-(V/P)^2)/(O-log(V/P))) ' is not a valid expression or equation.
Error in ==> solve at 67
[eqns,vars] = getEqns(varargin{:});
Error in ==>bufferoil at 4
solve('A*G*sqrt((1-(P/G)^2)/(N-log(P/G))) = B*P*sqrt((1-(V/P)^2)/(O-log(V/P)))', 'P')
回答(2 个)
Sean de Wolski
2011-6-10
I don't know why that's happening, but by breaking it into two lines I get an "explicit solution could not be found result"
syms A G P N B V O;
q = A*G*sqrt((1-(P/G)^2)/(N-log(P/G)));
z = B*P*sqrt((1-(V/P)^2)/(O-log(V/P)));
solve('q = z', P)
Addendum: elaborating on this
solve(q,P)
ans =
G
-G
solve(z,P)
Warning: Explicit solution could not be found.
> In solve at 81
ans =
[ empty sym ]
so the right hand side appears to be the issue.
5 个评论
Vito
2011-6-10
Sean de Wolski
2011-6-10
I trust the Symbolic Math toolbox enough to believe that there actually is not a solution to your equation.
Walter Roberson
2011-6-10
solve(z,P) should return V, -V
Sean de Wolski
2011-6-10
well it doesn't my system ? Are you sure?
Walter Roberson
2011-6-10
"should" as in they are obvious roots that Maple easily returns. The 1-(V/P)^2 clearly becomes 0 if V/P is +/- 1 .
Walter Roberson
2011-6-10
Your "syms" command is bogus -- it needs a bunch of spaces, like Sean shows. On the other hand, you do not make use of the symbolic property of those names in the code you show.
There is a solution to the equation, but it isn't very useful:
V/exp(RootOf(-Z*A^2*(exp(Z))^2*G^2 + Z*A^2*V^2 - V^2*B^2*N + V^2*B^2*ln(V/G) - V^2*B^2*Z + V^2*B^2*N*(exp(Z))^2 - V^2*B^2*(exp(Z))^2*ln(V/G) + V^2*B^2*(exp(Z))^2*Z + G^2*O*A^2*(exp(Z))^2 - O*A^2*V^2,Z))
where RootOf(expression,Z) indicates that one should substitute there the values of Z for which the expression becomes 0.
It is not possible to solve this using roots() because the coefficients of the pseudo-polynomial include exp(Z). It is also not suitable for conversion to a LambertW expression.
The equation has every (finite?) number as a root if both V and A are 0 (and possibly in other circumstances.)
4 个评论
Vito
2011-6-10
Walter Roberson
2011-6-10
I used Maple, reformatted the output very slightly to account for a syntax difference between Maple and MuPad.
Vito
2011-6-10
Walter Roberson
2011-6-10
Inside the symbolic toolbox, ln() is natural log, and log(b,x) is log of x base b. I do not at the moment see log(x) documented as being an alias for ln(x) so your use of log() with one argument might have confused it. This should not apply to log() at the MATLAB level, which is the natural log even when applied to a symbolic answer.
sqrt() should be fine either inside MuPad or at the MATLAB level.
sqrt()
类别
在 帮助中心 和 File Exchange 中查找有关 Common Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!