Crazy MATLAB Graph: Solving Simple Pendulum Eqns

  • MATLAB
  • Thread starter Chairman Lmao
  • Start date
  • Tags
    Graph Matlab
In summary: However, even with a small stepsize, there will still be some numerical error, which is why you are seeing these fluctuations. The code you provided seems to be correct, so this is most likely the cause of the unexpected graph. In summary, the weird linearly decreasing graph with periodic fluctuations is due to numerical error from using the Runge-Kutta method to numerically solve the simple pendulum equations.
  • #1
Chairman Lmao
17
0
Crazy MATLAB graph!

Hi!
I had been trying to numerically solve the simple pendulum equations using RK4 method in matlab. I had plotted the energy versus time graph. One would expect it to be just a straight line parallel to time axis. However, we got a weird linearly decreasing graph with periodic fluctuations, though the range in which the values were fluctuating was very small. Could anyone please explain this?
http://yfrog.com/89matlabj<-link for the graph(Energy vs time in s). The initial angle was 90deg and initial angular momentum 0.

If it helps, this was my code:

function z = pro1a(x,y)
q=zeros(1,6000);
p=zeros(1,6000);
t=zeros(1,6000);
E=zeros(1,6000);
q(1)=x;
p(1)=y;
t(1)=0;
E(1)=y.^2/2-9.8*cos(x);
for i=2:6000
k1=p(i-1);
j1=-9.8*sin(q(i-1));
k2=p(i-1)+0.005*j1;
j2=-9.8*sin(q(i-1)+0.005*k1);
k3=p(i-1)+0.005*j2;
j3=-9.8*sin(q(i-1)+0.005*k2);
k4=p(i-1)+0.01*j3;
j4=-9.8*sin(q(i-1)+0.01*k3);
q(i)=mod(q(i-1)+0.01*(k1+2*k2+2*k3+k4)/6,4*pi);
if q(i)>2*pi
q(i)=q(i)-4*pi;
end
p(i)=p(i-1)+0.01*(j1+2*j2+2*j3+j4)/6;
t(i)=t(i-1)+0.01;
E(i)=p(i).*p(i)./2-9.8.*cos(q(i));
end
plot(t,E);
z=max(E)-min(E)
end

x=initial angle
y=initial angular momentum
q=angle as function of time
p=angular momentum as function of time

Also, max(E)-min(E) was 4.893*10^(-7)

Thank you for your consideration! :)
 
Last edited:
Physics news on Phys.org
  • #2
It looks like the graph you are seeing is due to numerical error from using the Runge-Kutta method. The Runge-Kutta method is an approximate solution to the differential equations, meaning that it will not give an exact value (which would be a straight line parallel to the time axis). The periodic fluctuations you are seeing are probably due to the small stepsize used in the calculations. As the stepsize decreases, the numerical error decreases, resulting in a more accurate graph.
 

1. How can I use the "Crazy MATLAB Graph" to solve simple pendulum equations?

To use the "Crazy MATLAB Graph" to solve simple pendulum equations, you will first need to have MATLAB installed on your computer. Then, you can input the necessary equations and parameters into the MATLAB code and run it to generate the graph. The graph will show the motion of a pendulum over time, allowing you to analyze and solve the equations.

2. What are the benefits of using MATLAB for solving simple pendulum equations?

MATLAB is a powerful tool for solving equations and analyzing data. It allows for quick and accurate calculations, as well as the ability to visualize the results in graph form. This can make solving and understanding simple pendulum equations much easier and more efficient.

3. Can the "Crazy MATLAB Graph" be used for more complex pendulum systems?

Yes, the "Crazy MATLAB Graph" can be used for more complex pendulum systems as long as the equations and parameters are properly inputted into the code. However, for very complex systems, it may be necessary to use more advanced MATLAB features or other tools.

4. How can I verify the accuracy of the results from the "Crazy MATLAB Graph"?

You can verify the accuracy of the results from the "Crazy MATLAB Graph" by comparing them to known solutions or by running the equations through other mathematical software or tools. You can also check the code and inputs for any errors that may affect the accuracy of the results.

5. Are there any limitations to using the "Crazy MATLAB Graph" for solving simple pendulum equations?

The "Crazy MATLAB Graph" can be a useful tool for solving simple pendulum equations, but it does have some limitations. It may not be suitable for very complex systems or for analyzing systems with non-linear behavior. Additionally, the accuracy of the results may be affected by the quality of the input equations and parameters.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
697
  • Calculus and Beyond Homework Help
Replies
4
Views
974
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top