solving 4th order ode

19 Ansichten (letzte 30 Tage)
Roi Bar-On
Roi Bar-On am 1 Okt. 2019
Kommentiert: Elayarani M am 23 Sep. 2020
Hello everyone! I would appreciate your help in this section.
I have this 4th order,non-linear ,homogeneous ode that I would like to solve:
(2B+1+y)y''-k(1+y)y''''=0 with: y(0)=y(L)=0;y'(0)=y'(L)=1; where B,k and L are constants.
This is my matlab code so far:
L=1;B=0.25;k=0.1;
dydt = zeros(4,1);
dydt(1)=y(2);
dydt(2)=y(3);
dydt(3)=y(4);
dydt(4)=((2.*B+1+y(1)).*y(3))./(k.*(1+y(1)));
y1(1)=0; y1(end)=0; y2(1)=1; y2(end)=1;yint=[y1(1);y1(end);y2(1);y2(end)];
tspan = [0 1];
[t,y] = ode45(@(t,y) dydt, tspan, yint);
plot(t,y,'-o')
I think that something is not right. I have almost no expericance with solving ode's with MATLAB, especially with this high order so basically I gathered pieces of codes from things I saw online with the hope that it will assemble to a reasonable solution. I'm not sure I'm in a good path at all. I would be grateful for some guidance. Roi

Akzeptierte Antwort

darova
darova am 1 Okt. 2019
Use bvp4c()
You already have written your equation as system of first-order equations
function dydt = ode4(t,y)
L=1;B=0.25;k=0.1;
dydt = zeros(4,1);
dydt(1)=y(2);
dydt(2)=y(3);
dydt(3)=y(4);
dydt(4)=(2.*B+1+y(1)).*y(3))./(k.*(1+y(1));
end
Here is function for your boundary conditions
function res = bc4(y0, y1)
res = [y0(1)-0 % y(0) = 0
y0(2)-1 % y'(0) = 1
y1(1)-0 % y(end) = 0
y1(2)-1]; % y'(end) = 1
end
See bvp4c
  21 Kommentare
Roi Bar-On
Roi Bar-On am 19 Nov. 2019
Finally I understood your explanation and the rational, sorry for being so ignorent in this topic.
I've manually ran the code step by step and I see that basically nothing really happens. Basically we're giving the initial guess x=1 and the plot is just getting values of 1 eveywhere because 1 is really a solution. It seems that the code doesn't look for any other solutions and therefore I'm not getting any physical results. This is the final code for now:
function shooting_method
clc
clear all
x=1;
x1=fzero(@solver,x);
end
function F=solver(x)
options=odeset('RelTol',1e-8,'AbsTol',[1e-8,1e-8]);
[t,u]=ode45(@equation,[0 1],[x 1e-8],options);%1e-8 is for the function and x is for the derivative%ode15s,ode23s are options as well
s=length(t);
F=u(s,2)-0; %y'(1)=0
figure(1)
plot(t,u(:,1))
xlabel('x')
ylabel('rho')
title('S.M')
end
function dy=equation(~,y)
dy=zeros(2,1);
dy(1)=y(2);
A=1;E=1;
dy(2)=1./A.*log10(E.*y(1));
end
I would be glad for some help. Maybe this method isn't stable enough or the problem is stiff? If so do you happen to know any other method that might help me solve that problem?
Thanks,
Roi
darova
darova am 19 Nov. 2019
I tried this
x=0.5;
x1=fsolve(@solver,x);
And set limits for y axis:
ylim([0 2])
THe result (y'(0)=y'(1)=0.):
gif_animation.gif

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Roi Bar-On
Roi Bar-On am 7 Nov. 2019
Thanks,
Roi
  1 Kommentar
Elayarani M
Elayarani M am 23 Sep. 2020
Hi. I want to solve the following equation using ode45 solver.
How to set the initial conditions?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by