how to solve this non-linear equations?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
M.Rameswari Sudha
el 4 de En. de 2020
Comentada: M.Rameswari Sudha
el 18 de Dic. de 2020
I couldnot find the value of v and w. let me know what is the mistake in the following code.
function solveeqs()
guess=[200 110];
[result,fval,exit,output]= fsolve(@eqns,guess);
result
fval
eqns(guess)
output
end
function fcns=eqns(z)
v=z(1);
w=z(2);
p=30;d=1;lamda=0.8;c=10;r=35;h=0.05;chi=1000;k=0.02;b=7;a =0.01;T =107;
%w=k*(1-exp(-a*chi));
M=k*a;
fcns(1)=(1/T)*[p*d-((lamda*p*d*v)/T)-(d*exp(-(w-k)*v)-(d*v/T))*c-d*((v/T)-1)*r-(d/(w-k))*(1-exp(-(w-k)*v)*h)];
fcns(2)=(1/T)*[-(d*c*v*exp(-(w-k)*v)*M/(w-k))+(((d*c*(1-exp(-(w-k)*v))+h*d*v*(1+exp(-(w-k)*v)))*M)/(w-k)^2)+((2*h*d*(exp(-(w-k)*v)-1)*M)/(w-k)^3)-1];
end
3 comentarios
John D'Errico
el 4 de En. de 2020
Please don't use an answer to make a comment.
"how do u get ? I didnot get the answer. let me know what is the mistake made by me"
Respuesta aceptada
John D'Errico
el 4 de En. de 2020
Editada: John D'Errico
el 4 de En. de 2020
It is pretty easy to find at least one solution. vpasolve will do so, and my guess is, fsolve will do the same.
syms v w
p=30;d=1;lamda=0.8;c=10;r=35;h=0.05;chi=1000;k=0.02;b=7;a =0.01;T =107;
M=k*a;
fcns(1)=(1/T)*[p*d-((lamda*p*d*v)/T)-(d*exp(-(w-k)*v)-(d*v/T))*c-d*((v/T)-1)*r-(d/(w-k))*(1-exp(-(w-k)*v)*h)];
fcns(2)=(1/T)*[-(d*c*v*exp(-(w-k)*v)*M/(w-k))+(((d*c*(1-exp(-(w-k)*v))+h*d*v*(1+exp(-(w-k)*v)))*M)/(w-k)^2)+((2*h*d*(exp(-(w-k)*v)-1)*M)/(w-k)^3)-1];
sol = vpasolve(fcns,v,w)
sol =
struct with fields:
v: [1×1 sym]
w: [1×1 sym]
sol.v
ans =
98.167804480477247473056536377199
sol.w
ans =
0.070053725915927256484131799766249
Nonlinear solvers find a solution based on the starting guess. Use different start guesses, and you will find other solutions. vpasolve uses a default starting guess at (0,0) as I recall.
So where do the solutions lie? This is most easily done using a contour plot.
f1 = @(v,w) (1/T)*[p*d-((lamda*p*d*v)/T)-(d*exp(-(w-k).*v)-(d*v/T))*c-d*((v/T)-1).*r-(d./(w-k)).*(1-exp(-(w-k).*v)*h)];
f2 = @(v,w) (1/T)*[-(d*c*v.*exp(-(w-k).*v).*M./(w-k))+(((d*c*(1-exp(-(w-k).*v))+h*d*v.*(1+exp(-(w-k).*v)))*M)./(w-k).^2)+((2*h*d*(exp(-(w-k).*v)-1)*M)./(w-k).^3)-1];
H1 = fcontour(f1,[-200,200,-.25 .25]);
H1.LineColor = 'b';
H1.LevelList = 0;
hold on
H2 = fcontour(f2,[-200,200,-.25 .25]);
H2.LineColor = 'r';
H2.LevelList = 0;
grid on
xlabel 'v'
ylabel 'w'
Intersections of the red and blue lines indicate all solutions. There appear to be 6 solutions. Start in the vicinity of each solution, and you will get one of them.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/259706/image.jpeg)
The shape of the curves suggests there may be more solutions for large negative values of v, but I doubt it, as that would force w to change sign as we follow along that curve. More likely, the red curve will approach the asymptote at w==0 from below.
So, what did you do incorrectly? If fsolve failed to find at least one solution, then you should show what you did, and what error was the result.
I would conjecture the problem lies in your starting guess, which is terrible.
guess=[200 110];
which has a ridiculous initial value for w. 110 is so far out in the weeds, that it makes no sense in context of your equations.
p=30;d=1;lamda=0.8;c=10;r=35;h=0.05;chi=1000;k=0.02;b=7;a =0.01;T =107;
f1 = @(v,w) (1/T)*[p*d-((lamda*p*d*v)/T)-(d*exp(-(w-k).*v)-(d*v/T))*c-d*((v/T)-1).*r-(d./(w-k)).*(1-exp(-(w-k).*v)*h)];
f2 = @(v,w) (1/T)*[-(d*c*v.*exp(-(w-k).*v).*M./(w-k))+(((d*c*(1-exp(-(w-k).*v))+h*d*v.*(1+exp(-(w-k).*v)))*M)./(w-k).^2)+((2*h*d*(exp(-(w-k).*v)-1)*M)./(w-k).^3)-1];
solve(@(vw) [f1(vw(1),vw(2));f2(vw(1),vw(2))],[200,110])
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
141.92 88.652
So why do I suggest that w makes no sense? w always seems to be paired with k, which is 0.02 = 1/50.
pretty(fcns(1))
/ / 1 \ \
exp| -v | w - -- | |
\ \ 50 / / / / 1 \ \
-------------------- - 1 10 exp| -v | w - -- | |
20 \ \ 50 / / 49 v 65
------------------------ - ----------------------- - ----- + ---
/ 1 \ 107 11449 107
| w - -- | 107
\ 50 /
So w should be something on the order of k.
fsolve(@(vw) [f1(vw(1),vw(2));f2(vw(1),vw(2))],[100,.05])
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
98.168 0.070054
This system of equations is a bit tricky, as fsolve can return garbage solutions if you are not careful with the start guess. That is often true for problems that contain exponentials.
Más respuestas (1)
M.Rameswari Sudha
el 11 de Dic. de 2020
Editada: Walter Roberson
el 11 de Dic. de 2020
2 comentarios
Walter Roberson
el 11 de Dic. de 2020
You should start a new Question for this.
When you do, you should add more documentation as to what you are trying to solve.
for i=1:length(R1)
M1=(S*(r*Cp-(1-2*D/P)*r*Cv))/((A+R1(i))*(r*Cv*(1-D/P)+g*D*th0));
M(j)=M1;
j=j+1;
end
Why are you not just using
for i=1:length(R1)
M1=(S*(r*Cp-(1-2*D/P)*r*Cv))/((A+R1(i))*(r*Cv*(1-D/P)+g*D*th0));
M(i)=M1;
end
with no j ?
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!