Solving a system of higher order differential equations with ode45 ...error
Show older comments
Hello. I am an engineering student working on a rather simple problem but have exhausted my searches online and am not sure what is wrong with my setup. I have two equations, one third order and one second order differential equation. I also have 5 initial conditions where two of the initial conditions are guesses (namely f''(0) and g'(0)) - (typical guess between .5-1) when these guesses are correct the values of f'(large n) and g(large n) will converge to 1. The other three IC's are f(0)=0, g(0)=2.5, f'(0)=0. I wrote a code to reduce the order of the differential equations to a system of first order differential equations using the odeToVectorField command, then using matlab function and ode45 to 'solve' the system simultaneously... I likely have more than one mistake in here but am at a loss...I am getting NAN, complex doubles, and other nonsense outputs for the Sol structure...Any help would be appreciated. Also please let me know if I need to provide more information. Thank you.
% code
clear all
close all
syms g(n) f(n)
%
C=g^-(1/3);
Pr=.7;
gamma=1.4;
Me=3;
gw=1+sqrt(Pr)*((gamma-1)/2)*(Me^2) %Taw/T_e
EQ1=diff(C*diff(f,2))==-f*diff(f,2);
EQ2=diff((C/Pr)*diff(g))+f*diff(g)+(C*(Me^2*(gamma*(gamma-1))))*diff(f,2)^2==0;
EQS=[EQ1 EQ2];
V = odeToVectorField(EQS)
n=[0:1:10^2];
M = matlabFunction(V,'vars', {'n','Y'});
ICs=[f(0)==0,diff(f(0))==0,diff(f(0),2)==.75,g(0)==gw,diff(g(0))==.75] %not sure how to apply the 5 IC's to correspond to V - when i run this i get error div/0 - but oddly enough if I change around the order of the IC's the error is replaced with inputs must be type double, but then I get all NAN results I must be doing something really wrong. %
Sol = ode45(M,[n(1) n(end)],ICs)
end
3 Comments
Karan Gill
on 13 Nov 2017
If I may ask, what did you refer to when writing your code?
Eli
on 13 Nov 2017
Karan Gill
on 14 Nov 2017
Thanks! Glad to know people read my doc :) This page is also helpful: https://www.mathworks.com/help/symbolic/examples/solve-a-second-order-differential-equation-numerically.html
Lastly, if you have trouble with inputs, try reading the input arguments info in doc. Example: Here's ode45 input info.
Accepted Answer
More Answers (0)
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!