function main
clc
clear all
x=3;
options=optimset('Display','iter');
x1=fsolve(@solver,x,options);
function F=solver(x)
options=odeset('RelTol',le-8,'AbsTol',[le-8, le-8, le-8]);
[t,u]=ode45(@equation,[0,20],[4 -1 x],options);
s=length(t);
F=u(s,2);
figure(1)
plot(t,u(:,2))
hold on
end
end
function dy=equation(t,y)
dy=zeros(3,1);
dy(1)=y(2);
dy(2)=y(3);
dy(3)=y(2)^2-y(1)*y(3);
end
After running the above code following error occurs:
Not enough input arguments.
Error in fsolve (line 230)
fuser = feval(funfcn{3},x,varargin{:});
Error in (line 10)
x1=fsolve(@solver,x,options);
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

 채택된 답변

Star Strider
Star Strider 2019년 2월 23일

0 개 추천

You have a typographical error in your odeset call. You typed ‘l’ (lower-case ‘L’) instead of the number 1.
Use this instead:
options=odeset('RelTol',1e-8,'AbsTol',1e-8);
and your code runs without error.
When I ran it,, the result was:
x1 =
3.732

댓글 수: 7

MINATI
MINATI 2019년 2월 23일
Thanks for your quick and right response.
I need a single curve
But it gives multiple graphs(13) and it is taking so much time if I change
[t,u]=ode45(@equation,[0,20],[1 -1 x],options); % bold from 4 to 1(50 curves)
any modification needed in the program?
I am not certain what you want. If you want to plot a single curve (with the optimised value for the third initial condition), just plot the last one.
Try this:
x=3;
options=optimset('Display','iter');
x1=fsolve(@solver,x,options)
function F=solver(x)
options=odeset('RelTol',1e-8,'AbsTol',1e-8);
[t,u]=ode45(@equation,[0,20],[4 -1 x],options);
s=length(t);
F=u(s,2);
% figure(1)
% plot(t,u(:,2))
% hold on
% end
% end
function dy=equation(t,y)
dy=zeros(3,1);
dy(1)=y(2);
dy(2)=y(3);
dy(3)=y(2)^2-y(1)*y(3);
end
end
function dy=equation(t,y)
dy=zeros(3,1);
dy(1)=y(2);
dy(2)=y(3);
dy(3)=y(2)^2-y(1)*y(3);
end
[t,u]=ode45(@equation,[0,20],[4 -1 x1],options);
figure(1)
plot(t,u(:,2))
Esperiment to get the result you want.
MINATI
MINATI 2019년 2월 23일
Dear STAR
many many thanks.
It worked now.
Thanks
Star Strider
Star Strider 2019년 2월 23일
As always, my pleasure.
MINATI
MINATI 2019년 2월 24일
[t,u]=ode45(@equation,[0,20],[4 -1 x1],options);
what is the significance of 4 in [4 -1 x1]
Star Strider
Star Strider 2019년 2월 24일
It is one of the initial conditions for your ‘equation’ function differential equation system.
Rik
Rik 2019년 2월 24일
Related question in this new thread.

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

추가 답변 (0개)

카테고리

질문:

2019년 2월 23일

댓글:

Rik
2019년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by