Need help with solving differential equation using multiple initial values!
11 views (last 30 days)
Show older comments
Hello!
I am to solve a differential equation for a school project, and am to plot a solution curve given an intial angle and depth.
I wrote the following:
function dZ=trace(~,Z)
p = [5.6596 14.5820 257.4318];
c=@(z) 4800+p(1)+((p(2))*z/1000)+((p(3))*exp(-z/1000)); % c(z)
c=c(2000);
% inital conditions are given by: Z(1), the speed, and Z(2), the angle.
dZ=zeros(2,1);
dZ(1)=Z(2);
n=7.8;
q0=(c/cosd(n))^2;
dZ(2)=-q0*(((-p(3)/1000)*exp(-Z(1)/1000))+p(2)/1000)/((4800+p(1)+(p(2)*Z(1)/1000)+(p(3)*exp(-Z(1)/1000))^3));
end
The above is my function file for solving a second order ODE, who I then call using the following:
[X,Z]=ode45(@trace,[0:6076*25],[2000 tand(7.8)]); %solves the differential equation.
plot(X(151700:end),Z(151700:end,1),'-r') %plots a solution curve for z(x)
My problem then arises when I am to solve for multiple values of n, i.e, for angles ranging between -10-14 degrees. I could change my function 'trace' to take another input 'n', which I then specify in my other script (maybe by way of a for-loop?), but the ode45 solver does to accept this additional parameter. Also, this would mean slightly different values for the variable 'q0' each time I have a different n, and it being a part of the ODE, means slightly different diff equations for me to solve.
How to I change my code to accommodate this additional issue? Any insight/tips would be much appreciated!
0 Comments
Accepted Answer
More 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!