Find difficult in solving these four coupled ODE's using ODE45....I have attached a file regarding these equations..

function dy=pair(t,y,a,b,d,hstress,sigma,Hstar,kc,c)
dy(1)= a*sinh((b*(sigma^d)*(1-y(2)))/((1-y(3))*(1-y(4)))) ;
dy(2)=((hstress*(a*sinh(b*(sigma^d)*(1-y(2)))/(1-y(3))*(1-y(4))))/(sigma^d))*(1-y(2)/Hstar);
dy(3)=(kc/3)*power((1-y(3)),4);
dy(4)= c*y(1);
dy=dy';
end
Error
>> a=0.5179;
>> b=1.1003E-3;
>> c=0.4576;
>> d=1;
>> hstress=3463.46;
>> Hstar=0.7846;
>> Kc=0.1137;
>> tspan=0:0.01:40;
pair
Error using pair (line 3)
Not enough input arguments.
>> pair
Error using pair (line 3)
Not enough input arguments.
>> [t,y]=ode45(@pair,tspan,[0 0 0 0 0]);
I suspect I know a bit of what's going wrong, yet I'm at a loss for how to fix it. Any help is much appreciated!

 Réponse acceptée

a=0.5179;
b=1.1003E-3;
c=0.4576;
d=1;
hstress=3463.46;
Hstar=0.7846;
Kc=0.1137;
tspan=0:0.01:40;
initial_conditions=[0;0;0;0] %change the intial condition according to your values
[t,y]=ode45(@(t,y)pair(t,y,a,b,d,hstress,sigma,Hstar,Kc,c),tspan,initial_conditions) %function call
plot(t,y(:,1))
function dy=pair(t,y,a,b,d,hstress,sigma,Hstar,kc,c) %function definition
dy=zeros(4,1);
dy(1)=a*sinh((b*(sigma^d)*(1-y(2)))/((1-y(3))*(1-y(4)))) ;
dy(2)=((hstress*(a*sinh(b*(sigma^d)*(1-y(2)))/(1-y(3))*(1-y(4))))/(sigma^d))*(1-y(2)/Hstar);
dy(3)=(kc/3)*power((1-y(3)),4);
dy(4)=c*y(1);
end
Screen Shot 2018-11-25 at 11.29.29 AM.png

11 commentaires

I am getting an error.." function definitions are permitted are in this context"..
Please reply how to fix this error..
store the code from the function line onwards in pair.m
Just do what sir Walter says or copy the whole answer and paste it in a script , save it and run it
putting everything into aa script requires r2016b or later which II suspect the user does not have .
yes sir Walter I agree , @Ruban save the function as pair.m(same name of the function) and try the rest of the code in a separate file , this will get you to the solution.
First of all, thank u so much for your help...
Last thing..
Code is working as per you said... But one thing
it runs for only t=10; even tspan is given upto 40...
Even if we increases the tspan, it plots the curve only upto 10...
What could be the error??
I attached the snapshot which I got in the matlab?? please find the attachment.
no everything is alright see my attached picture in my answer , the x-axis represents the time
Sorry sir to disturb you..
The same error continues.. The curve shows upto t=10..
Even I tried with higher version (MATLAB 2018a)..
and which version of MATLAB you are using ??
Even in the program, you didn't give the input of sigma =180; but it is running for you...
Please help me to sort out this error?
Warning: Failure at t=9.795692e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (2.842171e-14) at time t.
> In ode45 (line 360)
y(4) goes to 1. You have
dy(1)=a*sinh((b*(sigma^d)*(1-y(2)))/((1-y(3))*(1-y(4)))) ;
so 1-y(4) goes to 0, and that is a denominator so dy(1) goes to infinity.
Is the function wrong sir ?? as per your comments sir..

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by