Question


Please show the Matlab code language C or fortran


Introduction In Exercise 5 you plotted a sinusoid describing the motion of a pendulum. Lets write a program to animate the m

where θ-angle of pendulum in radians θο initial angle of pendulum in radians g- acceleration due to gravity, 9.81 m/s2 L = le

Introduction In Exercise 5 you plotted a sinusoid describing the motion of a pendulum. Let's write a program to animate the motion of the pendulum. In order to make it realistic, it will not work perfectly the first time, and we'll have to modify and refine it to get it just right. Design Let's first write down the code description as delineated above. 1. Requirements a. b. Animate the motion of a pendulum. Output will be an animation of a stick with a bob on the end, moving according to appropriate physical laws. User will supply the length of the pendulum, the initial angle of the pendulum, and the length of time the animation is to run. c. d. Sketch: 91 "Х 2. Interface Name of function will be entered at the command line along with the parameters noted above in 1c as arguments. a. 3. Equations/Methods
0 0
Add a comment Improve this question Transcribed image text
Answer #1


axis (-15 15 -15 15]); Matlab function for drawing filled function p-circle (r,c, col) ⅝// radíus // center c[3 3] t// number

%%Matlab code for animation of pendulum
clear all
close all

%function for pendulam equation
theta=@(th0,g,L,t) th0*cos((sqrt(g/L))*t);

    %theta=angle of pendulum in radian
    %th0 =initial angle of pendulum in radian
    %g    =accelaration due to gravity, 9.81 m/s^2
    %L    =Length of the pendulam
    %t    =time sec
%All parameter values
L=10;
g=9.81;
th0=deg2rad(70);
t=linspace(0,10,500);
figure(1)

%loop for animation for all time period
for i=1:length(t)
    thta=theta(th0,g,L,t(i));
    x=L*sin(thta);
    y=L*cos(thta);
  
    %Plotting the pendulum
    %// radius
    r = 2;
    %// center
    c = [x -y];
    hold on
    %plotting the bob
    p1=circle(r,c,'red');
    %plotting the line
    p2=plot([0 x], [0 -y],'linewidth',3,'color','b');
    xlabel('x')
    ylabel('y')
    title('animation for pendulum')

    hold off
    axis([-15 15 -15 15]);
    pause(0.01)
    delete(p1)
    delete(p2)
end


figure(1)
hold on
p1=circle(r,c,'red');
p2=plot([0 x], [0 -y],'linewidth',3,'color','b');
hold off
axis([-15 15 -15 15]);

%Matlab function for drawing filled
function p=circle(r,c,col)
%// radius
%r = 2;
%// center
%c = [3 3];
%// number of points
n = 1000;
%// running variable
t = linspace(0,2*pi,n);

x = c(1) + r*sin(t);
y = c(2) + r*cos(t);

%// draw filled polygon
p=fill(x,y,[1,1,1],'FaceColor',col,'EdgeColor','none');
end


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

Add a comment
Know the answer?
Add Answer to:
Introduction In Exercise 5 you plotted a sinusoid describing the motion of a pendulum. Let's writ...
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