Boundary conditions in ode

Hello, I have a question. It would be greatly appreciated if someone could help me out. How can I define these boundary conditions in the following code ? y'(80)=0 and y(C0)=t0.
syms y(x) x Y
N=5;
r=0.05;
m=0.01;
p=1;
s=1;
t=0.1;
a=0.25;
b=0.25;
C0=1;
C=5;
f=(x+((x^2)+4*r*x*(1-a-b))^0.5)/(2*(1-a-b));
%t1=-(N+r+t*p*s-m);
Dy = diff(y);
D2y = diff(y,2);
t0= (((1-a)/a)*(1/r)^((a+b)/(1-a-b));
ode = y-(((1-a)/a)*(1/(r+f))^((a+b)/(1-a-b))+Dy*(C-x-m-(s^2))+0.5*D2y*(x^2)*(s^2)-(s^2)*x*Dy)/(r-m);
[VF,Subs] = odeToVectorField(ode);
odefcn = matlabFunction(VF, 'Vars',{x,Y});
tspan = [C0 C];
ic = [t0 0];
[x1,y1] = ode45(odefcn, tspan, ic);
figure
plot(x1,y1(:,1), 'DisplayName','(x_1,y_1_1)')

6 commentaires

Torsten
Torsten le 23 Avr 2023
Modifié(e) : Torsten le 23 Avr 2023
Didn't I tell you that you have to use bvp4c instead of ode45 for boundary value problems ?
Further, t0 is a function of y'. So what do you mean by y(C0) = t0 ?
John D'Errico
John D'Errico le 23 Avr 2023
You cannot use ODE45 to solve a boundary value problem. Try as hard as you want, if the conditions fall at both ends of the domain, then ODE45 is not an option. You cannot make software do what it is not written to do.
Fatemeh
Fatemeh le 23 Avr 2023
Thank you @Torsten and @John D'Errico.
@Torsten I edited the code. Thank you for pointing out the error.
Torsten
Torsten le 23 Avr 2023
Modifié(e) : Torsten le 23 Avr 2023
After the line
odefcn = matlabFunction(VF, 'Vars',{x,Y});
use the code I gave you for your previous problem. In bcfun, just replace yb(1) by yb(2).
And there is a ( too much in the definition of t0.
Fatemeh
Fatemeh le 23 Avr 2023
Thanks and what does yb(2) mean?
Torsten
Torsten le 23 Avr 2023
Modifié(e) : Torsten le 23 Avr 2023
It means that the second function you want to solve for (i.e. y') in the right boundary point (b) (i.e. x = 80) should be 0.
And ya(1) - t0 means that the first function you want to solve for (i.e. y) in the left boundary point (a) (i.e. x = C0) should be t0.
Here are examples to study on how to use bvp4c:

Connectez-vous pour commenter.

Réponses (0)

Tags

Question posée :

le 23 Avr 2023

Modifié(e) :

le 23 Avr 2023

Community Treasure Hunt

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

Start Hunting!

Translated by