how to solve this non-linear equations?

조회 수: 6 (최근 30일)
M.Rameswari Sudha
M.Rameswari Sudha 2020년 1월 4일
댓글: M.Rameswari Sudha 2020년 12월 18일
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
John D'Errico
John D'Errico 2020년 1월 4일
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"
M.Rameswari Sudha
M.Rameswari Sudha 2020년 3월 18일
Thank you for giving the answer. sorry for the delay response.

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2020년 1월 4일
편집: John D'Errico 2020년 1월 4일
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.
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.
  댓글 수: 1
M.Rameswari Sudha
M.Rameswari Sudha 2020년 3월 18일
Thank you for giving the answer. sorry for the delay response. Both are give the same solution with different concept. Thanks a lot

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

M.Rameswari Sudha
M.Rameswari Sudha 2020년 12월 11일
편집: Walter Roberson 2020년 12월 11일
I am unable to find the answer. let me know what is the mistake in the following code.
clc
clear all
D=1000;
P=3200;
A=25;
S=200;
Cp=25;
Cv=20;
r=0.2;
k=2.33;
I=0.1;
g=15;
th0=0.0002;
R1=[0 5.6 22.4 57.4];
j=1;
l=1;
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
M
for p=1:1:4
for m=2:1:6
if m*(m-1)<=M(p) && m*(m+1)>=M(p)
x1=m
else
x2=m;
end
end
end
x1;
m1=[3 3 2 2]
c=1;
z1=1;
b=1;
for z=2:20
for w=1:4
for y=1:1:20
Q1=sqrt((2*D*(A+(S/m1(w)))+R1(w))/(r*(Cv*(m1(w)*(1-D/P)-1+2*D/P)+Cp)+g*m1(w)*D*th2(y)));
q=400*log(0.0002/th2(y));
theta2=(2*I*q)/(g*m1(w)*D*Q1(y));
th2(b)=theta2;
Q(b)=Q1;
b=b+1;
end
b=b-1;
if ((Q(z)~=Q(z-1)) | (th2(z)~=th2(z-1)))
z1=z1+1
else
break
end
end
end
TC(m1)=(D/Q1(i))*(A+S/m1(i)+R)+(Q1(i)/2)*((m1(i)*(1-D/P)-1+2*D/P)*r*Cv+r*Cp+g*m1(i)*D*theta)+r*Cp*k*sigma*sqrt(L)+i*q*log(th0/theta);
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 12월 11일
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 ?
M.Rameswari Sudha
M.Rameswari Sudha 2020년 12월 18일
No. I couldn't get the answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by