solving 4th order ode

19 次查看(过去 30 天)
Roi Bar-On
Roi Bar-On 2019-10-1
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

采纳的回答

darova
darova 2019-10-1
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 个评论
Roi Bar-On
Roi Bar-On 2019-11-19
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 2019-11-19
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

请先登录,再进行评论。

更多回答(1 个)

Roi Bar-On
Roi Bar-On 2019-11-7
Thanks,
Roi
  1 个评论
Elayarani M
Elayarani M 2020-9-23
Hi. I want to solve the following equation using ode45 solver.
How to set the initial conditions?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by