How to find the value of a variable in MATLAB that exists on both sides of th eequal sign?

15 次查看(过去 30 天)
Does anybody know how we can find the value of a variable in MATLAB that exists on both sides of equal sign, e.g. n in 2n+q=n+r (n is the only variable)?
In this case it is so simple; n=r-q. But what if the equation is very complex and we are not able to transfer the variable to one side?

采纳的回答

Star Strider
Star Strider 2014-5-16
If you have the Symbolic Math Toolbox:
syms n q r
Eq = 2*n+q == n+r
n = solve(Eq, n)
produces:
n =
r - q
To solve them numerically for n, make the entire equation equal to zero and use the fzero function:
r = 3;
q = 5;
f = @(n) [2*n+q - (n+r)];
n = fzero(f, 1)
produces:
n =
-2
  4 个评论
Kourosh
Kourosh 2014-5-19
Dear Star,
I have one specific problem in my case. What you mentioned is correct. But in my case with the funntion
su=1; b=0.5; l=1.571; p=0.16; t=atan(2*pi()/p); Landa=-tan((pi()/2)-t);
pn=p/l; B=asin(pn);
q=0.49*pn^-0.55; r=0.76*pn^-0.55;
Nmax=4.266*cos (B)*((b/l)/0.318)*su*l^2; Tmax=0.191*((b/l)/0.318)*su*l^3;
f = @(Nn) [((Nn/Nmax)^(q-1))/(1-(Nn/Nmax)^q)^((r-1)/r)-(r*Landa*Nmax/(q*Tmax))];
Nn = fzero(f, 0)
where I know the result is definitely between 0 and 10, the result by Matlab is NaN.
I am pretty sure the equation is correct. Is there any other way to solve it?
Cheers, Cyrus
Star Strider
Star Strider 2014-5-19
I don’t know what the equation is, but plotting it:
Nn = linspace(-10,10);
figure(1)
plot(Nn, real(f(Nn)))
grid
shows that the real part doesn’t have a zero crossing anywhere in the region. (It has a small region in the Nn domain where it generates complex values.)

请先登录,再进行评论。

更多回答(1 个)

Brian B
Brian B 2014-5-16
If you have the Symbolic Toolbox, you can use:
>> syms n q r
>> solve('2*n+q=n+r','n')
ans =
r - q

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by