Solving a Third order ODE
9 views (last 30 days)
Show older comments
I have been having some trouble solving what I feel like is a simple Third Order ODE in Matlab so I was wondering if there is something obvious that I am doing wrong. My equation is
A'''=((420/(11*Re0))+(g(i)*h(i)+84/11*f(i)*g(i)-35/11*NClam/Re0*h(i)-70/11*Cturb*g(i)*h(i)-70/11*1/Re0*h(i))/f(i);
Where f = A, g = A', h = A'' and the other terms are all constants, Re0 = 28640, NClam = 30*10^6, Cturb = 58. My Boundary Conditions are f(0)=0, g(0)=0, and f(1)=1. I'm using this last boundary condition to shoot for h(0)=?. I have been having some issues because part of the equation is divided by f, so at 0, I can't get a real solution. My code is below, I was hoping someone could show me a way to solve this without getting inf from dividing by 0.
f=zeros(length(x),1); % f=A
g=zeros(length(x),1); % g=A'
h=zeros(length(x),1); % h=A''
A3=zeros(length(x),1); % A3=A'''
f(1)=.01; % Boundary Condition at dead end
g(1)=.001; % Boundary Condition at dead end
% 1st 2 Shooting Guesses
SG(1)=.0001;
SG(2)=.00011;
for j=1:2
h(1)=SG(j);
for i=1:size(x,1)-1
% Runge Kutta Slopes
k1f=dx*g(i);
k1g=dx*h(i);
k1h=dx*(420/(11*Re0))+(g(i)*h(i)+84/11*f(i)*g(i)-35/11*NClam/Re0*h(i)-70/11*Cturb*g(i)*h(i)-70/11*1/Re0*h(i))/f(i);
k2f=dx*(g(i)+1/2*k1g);
k2g=dx*(h(i)+1/2*k1h);
k2h=dx*(420/(11*Re0))+((g(i)+1/2*k1g)*(h(i)+1/2*k1h)+84/11*(f(i)+1/2*k1f)*(g(i)+1/2*k1g)-35/11*NClam/Re0*(h(i)+1/2*k1h)-70/11*Cturb*(g(i)+1/2*k1g)*(h(i)+1/2*k1h)-70/11*1/Re0*(h(i)+1/2*k1h))/(f(i)+1/2*k1f);
k3f=dx*(g(i)+1/2*k2g);
k3g=dx*(h(i)+1/2*k2h);
k3h=dx*(420/(11*Re0))+((g(i)+1/2*k2g)*(h(i)+1/2*k2h)+84/11*(f(i)+1/2*k2f)*(g(i)+1/2*k2g)-35/11*NClam/Re0*(h(i)+1/2*k2h)-70/11*Cturb*(g(i)+1/2*k2g)*(h(i)+1/2*k2h)-70/11*1/Re0*(h(i)+1/2*k2h))/(f(i)+1/2*k2f);
k4f=dx*(g(i)+k3g);
k4g=dx*(h(i)+k3h);
k4h=dx*(420/(11*Re0))+((g(i)+k3g)*(h(i)+k3h)+84/11*(f(i)+k3f)*(g(i)+k3g)-35/11*NClam/Re0*(h(i)+k3h)-70/11*Cturb*(g(i)+k3g)*(h(i)+k3h)-70/11*1/Re0*(h(i)+k3h))/(f(i)+k3f);
% Evaluation
f(i+1)=f(i)+1/6*(k1f+2*k2f+2*k3f+k4f);
g(i+1)=g(i)+1/6*(k1g+2*k2g+2*k3g+k4g);
h(i+1)=h(i)+1/6*(k1h+2*k2h+2*k3h+k4h);
end
% R is f at channel end, we want equal to Uout
R(j)=f(size(x,1));
err=abs(uout-(R(j)));
end
% This loop iterates to find the right guess for f''(0) so that
% f(x/L)= 1
while err>1e-9
j=j+1;
% New guess is found by linear interposation of the last 2 guesses
SG(j)=SG(j-2)+(SG(j-1)-SG(j-2))/(R(j-1)-R(j-2))*(-R(j-2));
h(1)=SG(j);
for i=1:size(x,1)-1
% Runge Kutta Slopes
k1f=dx*g(i);
k1g=dx*h(i);
k1h=dx*(420/(11*Re0))+(g(i)*h(i)+84/11*f(i)*g(i)-35/11*NClam/Re0*h(i)-70/11*Cturb*g(i)*h(i)-70/11*1/Re0*h(i))/f(i);
k2f=dx*(g(i)+1/2*k1g);
k2g=dx*(h(i)+1/2*k1h);
k2h=dx*(420/(11*Re0))+((g(i)+1/2*k1g)*(h(i)+1/2*k1h)+84/11*(f(i)+1/2*k1f)*(g(i)+1/2*k1g)-35/11*NClam/Re0*(h(i)+1/2*k1h)-70/11*Cturb*(g(i)+1/2*k1g)*(h(i)+1/2*k1h)-70/11*1/Re0*(h(i)+1/2*k1h))/(f(i)+1/2*k1f);
k3f=dx*(g(i)+1/2*k2g);
k3g=dx*(h(i)+1/2*k2h);
k3h=dx*(420/(11*Re0))+((g(i)+1/2*k2g)*(h(i)+1/2*k2h)+84/11*(f(i)+1/2*k2f)*(g(i)+1/2*k2g)-35/11*NClam/Re0*(h(i)+1/2*k2h)-70/11*Cturb*(g(i)+1/2*k2g)*(h(i)+1/2*k2h)-70/11*1/Re0*(h(i)+1/2*k2h))/(f(i)+1/2*k2f);
k4f=dx*(g(i)+k3g);
k4g=dx*(h(i)+k3h);
k4h=dx*(420/(11*Re0))+((g(i)+k3g)*(h(i)+k3h)+84/11*(f(i)+k3f)*(g(i)+k3g)-35/11*NClam/Re0*(h(i)+k3h)-70/11*Cturb*(g(i)+k3g)*(h(i)+k3h)-70/11*1/Re0*(h(i)+k3h))/(f(i)+k3f);
% Evaluation
f(i+1)=f(i)+1/6*(k1f+2*k2f+2*k3f+k4f);
g(i+1)=g(i)+1/6*(k1g+2*k2g+2*k3g+k4g);
h(i+1)=h(i)+1/6*(k1h+2*k2h+2*k3h+k4h);
end
% R is f at channel end, we want equal to Uout
R(j)=f(size(x,1));
err=abs(uout-(R(j)));
end
% Calculate A'''
for i = 1:length(x)
A3(i) = (420/(11*Re0))+(g(i)*h(i)+84/11*f(i)*g(i)-35/11*NClam/Re0*h(i)-70/11*Cturb*g(i)*h(i)-70/11*1/Re0*h(i))/f(i); end
0 Comments
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!