Solving for a variable in an equation

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 comentarios

Torsten
Torsten el 27 de Mzo. de 2025
Editada: Torsten el 27 de Mzo. de 2025
Plot the expression on the left-hand side of "eqn" as a function of N. I don't see it crosses the N-axis - thus no solution.
Maybe it could help if you include the 4 equations "eqn" is composed of.
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));
Sam Chak
Sam Chak el 27 de Mzo. de 2025
@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 el 27 de Mzo. de 2025
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.

Iniciar sesión para comentar.

Respuestas (2)

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 comentarios

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?
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;
limit(eqn, N, inf)
ans = 
vpa(ans)
ans = 
71.552190940962162246430199742351
Never reaches zero.
John D'Errico
John D'Errico el 27 de Mzo. de 2025
Editada: John D'Errico el 27 de Mzo. de 2025
A log scale is completely irrelevant. Your equation NEVER crosses zero.
Is there a better way? No. You cannot find a point where that crosses the x axis, so at y==0.
What you need to do is to go back to your problem. Have you made a mistake? Surely, if you think a solution should exist. You may be using the wrong equation. Maybe you formulated the mathematics incorrectly. But you have reached a point where an impossibility exists. There is no positive real solution to the equation you have formulated.
syms N
R = 0.1;
K = (sym(7516)/sym(10)^3*sym(10)^3)*N^-(sym(06738)/sym(10)^4) + sym(5339)/sym(10)^3;
M = (sym(5392)/sym(10)^3*sym(10)^3)*N^-(sym(01606)/sym(10)^4) + sym(190847)/sym(10)^3;
eqn = (1-R)*M*sqrt((((K/(1-R)*M)^2)*(1/sym(pi)))/(sym(1000) + (((K/(1-R)*M)^2)*(1/sym(pi))))) - sym(100);
limit(eqn, N, inf)
ans = 
simplify(ans)
ans = 
vpa(ans)
ans = 
71.552190940962154652693236881001
Sean Marcus
Sean Marcus el 28 de Mzo. de 2025
Thanks, I think I most likely made a mistake in rearanging the equations. I'll look at it more in depth tonight.
dpb
dpb el 28 de Mzo. de 2025
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.

Iniciar sesión para comentar.

dpb
dpb el 27 de Mzo. de 2025
Movida: dpb el 27 de Mzo. de 2025
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 comentarios

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 el 27 de Mzo. de 2025
Editada: dpb el 27 de Mzo. de 2025
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...

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 27 de Mzo. de 2025

Comentada:

dpb
el 28 de Mzo. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by