Question

Assignment 9.3: ODE Ill or pendulum Ill Solve the equation for the small amplitude pendulum without driving forces but with d

using Matlab

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Int we have to np+ itinto toso i^t or des-egm Let Initial comditons dtltoo dar So that diCo) a d 2- d toLemalab fn naw Here aclear all close all %all parameter values al0 0; a20-5; tin-0; t end - 10 ; %initial and final time h 0.005; Binitial quess ttime vs. Displacement plot 15 0.5 0.5 10 1.5 6 5 time time vs. Velocity plot 3. 10 6 5 time 2

clear all
close all
%all parameter values
a10=0; a20=5;     %initial guess
t_in=0; t_end=10; %initial and final time
h=0.005;          %step size
g=9.8; l=1;q=.5; %all parameter values
%all solution plot
[t_rk,a1_rk,a2_rk]= RK4_sol(t_in,t_end,a10,a20,h,g,l,q);
%Plotting data
figure(1)
plot(t_rk,a1_rk)
title('time vs. Displacement plot')
xlabel('time')
ylabel('displacement')

figure(2)
plot(t_rk,a2_rk)
title('time vs. Velocity plot')
xlabel('time')
ylabel('velocity')
%Function for RK4 solution
function [t_rk,a1_rk,a2_rk]= RK4_sol(t_in,t_end,a10,a20,h,g,l,q)
    %function forRK4 equation solution
    f1=@(t,a1,a2,g,l,q) a2;
    f2=@(t,a1,a2,g,l,q) (-g/l)*a1-q*a2;
  
        n=(t_end-t_in)/h; %number of steps
        a1_rk(1)=a10; a2_rk(1)=a20; t_rk(1)=t_in;
    %Runge Kutta 4 iterations
        for i=1:n
            k1=h*f1(t_rk(i),a1_rk(i),a2_rk(i),g,l,q);
            l1=h*f2(t_rk(i),a1_rk(i),a2_rk(i),g,l,q);
            k2=h*f1(t_rk(i)+h/2,a1_rk(i)+(1/2)*k1,a2_rk(i)+(1/2)*l1,g,l,q);
            l2=h*f2(t_rk(i)+h/2,a1_rk(i)+(1/2)*k1,a2_rk(i)+(1/2)*l1,g,l,q);
            k3=h*f1(t_rk(i)+h/2,a1_rk(i)+(1/2)*k2,a2_rk(i)+(1/2)*l2,g,l,q);
            l3=h*f2(t_rk(i)+h/2,a1_rk(i)+(1/2)*k2,a2_rk(i)+(1/2)*l2,g,l,q);
            k4=h*f1(t_rk(i)+h,a1_rk(i)+k3,a2_rk(i)+l3,g,l,q);
            l4=h*f2(t_rk(i)+h,a1_rk(i)+k3,a2_rk(i)+l3,g,l,q);
            t_rk(i+1)=t_in+i*h;
            a1_rk(i+1)=double(a1_rk(i)+(1/6)*(k1+2*k2+2*k3+k4));
            a2_rk(i+1)=double(a2_rk(i)+(1/6)*(l1+2*l2+2*l3+l4));
        end
end


%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
using Matlab Assignment 9.3: ODE Ill or pendulum Ill Solve the equation for the small amplitude pendulum without dri...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT