필터 지우기
필터 지우기

matlab vpasolve function not returning correct answer

조회 수: 6 (최근 30일)
mohamad khazaeezade
mohamad khazaeezade 2018년 1월 25일
댓글: Torsten 2018년 1월 25일
hi i have follow code:
clc
clear all
syms yn
b=3;
m=1;
S=0.001;
n=0.014;
Q=28;
A=(b+m*yn)*yn;
T=b+2*m*yn;
P=b+2*yn*sqrt(1+m^2);
R=A/P;
D=A/T;
Eq=Q==(A/n)*S^(0.5)*R^(2/3);
yn=vpasolve(Eq,yn)
matlb give me "yn=- 4.2710 + 2.1157*i " as a Mixed number but the true answer is "yn=2.128"
Why does Matlab say this answer?

채택된 답변

Birdman
Birdman 2018년 1월 25일
The problem is about initial guess of your equation. vpasolve can not correctly find an initial point and therefore returns a wrong value. My suggestion would be take a look of the graph of the function. First, run the following code:
syms yn
b=3;
m=1;
S=0.001;
n=0.014;
Q=28;
A=(b+m*yn)*yn;
T=b+2*m*yn;
P=b+2*yn*sqrt(1+m^2);
R=A/P;
D=A/T;
fun=Q-(A./n).*S.^(0.5).*R.^(2/3);
plot(-20:0.1:20,subs(fun,yn,-20:0.1:20),-20:0.1:20,subs(fun,yn,-20:0.1:20)==0,'*')
When you check the plot for the input vector and when you zoom in the red line crosses the function, you will see that it crosses when yn has a value of 2.1 or around it. Therefore, you need to set your initial guess argument accordingly, so that you will have an accurate solution. After this step, run the following code and see the result.
yn=vpasolve(fun,yn,3)
I chose 3 as initial point in this situation.

추가 답변 (1개)

Torsten
Torsten 2018년 1월 25일
Use
Eq=Q==(A/n)*S^(0.5)*(R^2)^(1/3);
instead of
Eq=Q==(A/n)*S^(0.5)*R^(2/3);
Best wishes
Torsten.
  댓글 수: 5
mohamad khazaeezade
mohamad khazaeezade 2018년 1월 25일
yn become -5.31 , and And that's wrong
Torsten
Torsten 2018년 1월 25일
-5.31 is a solution of your equation, but not the one you are looking for.
Setting an initial guess for the solution - like Birdman suggests - should help.
Or you could try to use
assume(yn>0)
Best wishes
Torsten.

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

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by