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
Sean de Wolski 2011 年 6 月 10 日

0 投票

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
Vito 2011 年 6 月 10 日
Yeah I already tried that too, you get the empty sym error. Does anyone feel that the natural log may be the issue and maybe I should try to further simplify the expression? I just feel like I would be working in circles trying to simplify.
Sean de Wolski
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
Walter Roberson 2011 年 6 月 10 日
solve(z,P) should return V, -V
Sean de Wolski
Sean de Wolski 2011 年 6 月 10 日
well it doesn't my system ? Are you sure?
Walter Roberson
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
Walter Roberson 2011 年 6 月 10 日

0 投票

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
Vito 2011 年 6 月 10 日
How did you come to that answer? As well I am sorry about the lack of spaces in the sym command, I realized afterwards that it got rid of the spaces when I copied it in.
Walter Roberson
Walter Roberson 2011 年 6 月 10 日
I used Maple, reformatted the output very slightly to account for a syntax difference between Maple and MuPad.
Vito
Vito 2011 年 6 月 10 日
hmm well I just downloaded maple so I will try that, thank you very much. One other question, is there a special way to be using sym with the log function or with sqrt?
Walter Roberson
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()

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

タグ

タグが未入力です。

質問済み:

2011 年 6 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by