Second Order Differential Equations to 2 First Order
Show older comments
I'm trying to turn <http://latex.codecogs.com/gif.latex?\frac{\mathrm{d^2}%20\theta%20}{\mathrm{d}%20t^2}%20=%20-sin\theta> to 2 first order differential equations so I can then use ode45 to solve them. With initial conditions theta(0)=0.1 and theta primed(0)=0, <http://latex.codecogs.com/gif.latex?\frac{\mathrm{d}%20\theta%20}{\mathrm{d}%20t}=%200>
Here is my attempt at it:
function xprime=first(t,x);
xprime(1)=x(2);
xprime(2)=-sin(x);
xprime=xprime(:);
I save this as a mfile.
Then use :
ts[1,10];
x0 = [0 1]
[t,s] = ode45('first',ts,x0);
I get the error :
n an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> first at 5 xprime(2)=-sin(x);
Now I have no clue how to correct this problem. I followed the guide here http://www.mathworks.com/support/tech-notes/1500/1510.html#reduce to no avail.
Anyone got any ideas? This is the first question on my assignment questions and the rest require this to be correct so am totally stuck at the moment.
Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!