Solving for a variable in an equation

3 ビュー (過去 30 日間)
Sean Marcus
Sean Marcus 2025 年 3 月 27 日
コメント済み: dpb 2025 年 3 月 28 日
Hello I have a matlab code below with an equation where I am trying to solve for N. However, everytime that I run the code it just runs forever and never gives me an answer. Any help would be great.
R = 0.1;
K = (7.516*10^3)*N^-0.6738 + 5.339;
Unrecognized function or variable 'N'.
M = (5.392*10^3)*N^-0.1606 + 190.847;
syms N
eqn = (1-R)*M*sqrt((((K/(1-R)*M)^2)*(1/pi))/(1000 + (((K/(1-R)*M)^2)*(1/pi)))) - 100 == 0;
S = solve(eqn)
This 1 equation comes from a system of 4 equations so if there is any other gbetter way to solve for it I am open to try different ways. Thanks
  4 件のコメント
Sam Chak
Sam Chak 2025 年 3 月 27 日
@Sean Marcus, I have two simple questions for you. From which textbook do all these nonlinear equations originate? Are there any examples of similar problems that we can refer to numerically solve for N?
Steven Lord
Steven Lord 2025 年 3 月 27 日
If these equations represent something physically realizable (a machine that you're hoping to build and need N as some physical measurement of one of the components) can you state what the units of the various constants and variables ought to be? I wonder if this is a problem of dimensional analysis, where one of the quantities has units of meters but it was supposed to be included in the equation as a length in kilometers or vice versa.

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

回答 (2 件)

John D'Errico
John D'Errico 2025 年 3 月 27 日
First, you need to recognize there is NO analytical solution to your problem. So using solve means it will just toss and turn forever.
Next, define N as a sym, BEFORE you use it in an equation!
syms N
R = 0.1;
K = (7.516*10^3)*N^-0.6738 + 5.339;
M = (5.392*10^3)*N^-0.1606 + 190.847;
eqn = (1-R)*M*sqrt((((K/(1-R)*M)^2)*(1/pi))/(1000 + (((K/(1-R)*M)^2)*(1/pi)))) - 100;
Remove the ==0, as that is implicit. But this allows us to plot it. I'll make it a function handle for better speed.
fun = matlabFunction(eqn);
fplot(fun,[0,1e15])
Hmm. I had to go out as far as 1e15, and it does not seem to be getting near zero.
fplot(fun,[0,1e30])
It looks like we can go on forever, and never reach zero. Do you see it seems to be slowing down, and will never get there?
While there may be complex roots, or negative roots, my guess is they would not be useful to you.
This means you may have made a mistake in generating this problem. We cannot know where the mstake lies. But there is no solution to be found.
  6 件のコメント
Sean Marcus
Sean Marcus 2025 年 3 月 28 日
Thanks, I think I most likely made a mistake in rearanging the equations. I'll look at it more in depth tonight.
dpb
dpb 2025 年 3 月 28 日
I believe also @Steven Lord's comment on dimensional analysis is quite a solid point to ensure -- the big numbers in there at least raise the uncertainty levels. And, again, if there were any background provided to go with the bare equations it could be enlightening as to where there could be an issue.

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


dpb
dpb 2025 年 3 月 27 日
移動済み: dpb 2025 年 3 月 27 日
function F=eqn(N)
R= 0.1;
K= (7.516*10^3)*N.^-0.6738 + 5.339;
M= (5.392*10^3)*N.^-0.1606 + 190.847;
F=(1-R).*M.*sqrt((((K./(1-R).*M).^2).*(1/pi))./(1000 + (((K./(1-R).*M).^2).*(1/pi)))) - 100;
end
fn=@eqn;
N0=1;
%N=fsolve(fn,N0)
fplot(fn,[1000 1E20])
N=logspace(1,20);
subplot(2,1,1)
K=(7.516*10^3)*N.^-0.6738 + 5.339;
K(end)
ans = 5.3390
loglog(N,K)
legend('K')
subplot(2,1,2)
M=(5.392*10^3)*N.^-0.1606 + 190.847;
M(end)
ans = 194.1564
loglog(N,M)
legend('M')
F=eqn(1E20)
F = 74.5342
The M, K terms approach asymptotic values as N gets large at roughly the final constant term. Evaluating your function at that point shows it's still quite a long way from 0 and will never get there...
figure
F=eqn(N);
F(end)
ans = 74.5342
semilogx(N,F)
ylim([0 1000])
  2 件のコメント
Sean Marcus
Sean Marcus 2025 年 3 月 27 日
The 4 equations are listed below where A_1 and W will be values that will be found expreimentally and then used to Solve for N. I might have rearranged these equations wrong and that is what is cuasing the issue.
K = (7.516*10^3)*N^-0.6738 + 5.339;
M = (5.392*10^3)*N^-0.1606 + 190.847;
A_0 = ((K/((1-0.1)*M))^2)*(1/pi);
W = (1-0.1)*M*sqrt(A_0/((A_1/1000000) + A_0));
It might help to say that this would be on a log scale.
As well this is a just a test for me. I am trying make a function that inputs A_0 and W and spits out N. If there is a better way to do this would you know?
dpb
dpb 2025 年 3 月 27 日
編集済み: dpb 2025 年 3 月 27 日
The fsolve formulation above works as template; of course it couldn't find a solution so I switched over to showing why. Recast that approach for a numerical solution instead of symbolic. Whether there will be a real solution will depend upon what the two unknown A and W are. K and M approach the constant term asymptotically as shown so you can make guesses about what the ranges could be for sanity checks. Is there any reason to think of a particular value/range for N?
It's possible if could explain what these represent somebody might recognize the problem...

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by