How can I create a runge kutta 4th order with no x variable?

1 view (last 30 days)
I am a total beginner at matlab. I am trying to solve the following second order differential equation:
d2y/dz2=(f/2EI)(L-z)
where f=51, E=1.1*10^8, I=0.05, L=27, step size=2.7 (which is 27/10). initial conditions: y=0, y'=0 at z=0
I am reducing the order of the equation to make it first order by using p and pdot.
p1=y,
p1dot=y'=p2
p2dot=y''=(f/2EI)(L-z)
below is the code:
function pdot=mast(t,p)
f=50; E=1.1E+08; I=0.05; L=27;
pdot=zeros(size(p));
pdot(1)=p(2);
pdot(2)=(f/2EI)(L-z);
>>p0=[0 0];
>>[t,p]=ode45('mast',[0 27],p0);
  1 Comment
John D'Errico
John D'Errico on 29 Nov 2015
Edited: John D'Errico on 29 Nov 2015
Please don't add answers every time you wish to make a comment. That is why there is a link that will let you add a comment. I moved your answer into a comment.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 29 Nov 2015
You have
pdot(2)=(f/2EI)(L-z);
Rmemeber that MATLAB does not have implicit multiplication.
pdot(2)=(f/(2*E*I))*(L-z);
But now you need to figure where you are getting "z" from.
  2 Comments
John D'Errico
John D'Errico on 29 Nov 2015
Moved to a comment:
"Hi Walter, Thank you for your response. I forgot to include the multipication sign between the two brackets in my question. They were included in Matlab though.
Can you explain what you mean by where am I getting the z from please?"
Walter Roberson
Walter Roberson on 29 Nov 2015
You say
p1=y,
p1dot=y'=p2
p2dot=y''=(f/2EI)(L-z)
but what is "z" in that?
Perhaps you should be using
function pdot = mast(z, p)
Notice the change from t to z

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!