0% found this document useful (0 votes)
44 views26 pages

Cm1-Lab Assignment

cm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views26 pages

Cm1-Lab Assignment

cm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

AMRITA VISHWA VIDYAPEETHAM

NAGERCOIL CAMPUS

AY 2024-25

LAB ASSIGNMENT

ASSIGNMENT TITLE : MATLAB PROGRAMMING


COURSE CODE : 23PHY104
COURSE NAME : COMPUTATIONAL MECHANICS 1

Submitted by:

ROLL NUMBER :24034


NAME :Ranjana.L
YEAR/SEMESTER :1
CLASS :AID

Marks Faculty Name Signature Remarks


LIST OF EXPERIMENTS
Week No. Expt. No. Experiment Name
1 a) To Know the history and features of MATLAB
b) To Know the local environment of MATLAB
2 a) Write a MATLAB code to find V according to the given formula,
P*V = n*R*T, the variables are given as P=10, n=2, R=7, and T= ½.
b) Write a MATLAB code to plot the function y=2sinx.
c) Write a MATLAB code to plot the function y = sinx with grids.
Then, keep the first graph and plot a second function given by y =
cos (x) within the same interval. Insert the labels for each data set,
as well.
3 a) Write a MATLAB code to plot the three functions sinx, cosx and
sinx+cosx on different axes on the same figure using the subplot
command.
b) Generate the MATLAB code to calculate the area and perimeter of a
circle, where the radius is entered by the user.
c) Write a MATLAB code to find the first order and second order
derivative of the given function f=x3-7x2+6x-61.
4 a) Write a MATLAB program to plot the position, velocity and
acceleration as a function of time for a particle moves along a
straight line is given by the position relation, x=t3-6t2-15t+40.

b) The motion of a particle is defined by the relation x=6t 4-2t3-


12t2+3t+3, where x and t are expressed in meters and seconds,
respectively. Write a MATLAB program to determine the time, the
position, and the velocity when a=0.

c) An automobile weighing 4000 lb is driven down a 5° incline at a


speed of 60 mi/h when the brakes are applied, causing a constant
total braking force (applied by the road on the tires) of 1500 lb.
Write a MATLAB program to determine the distance traveled by
the automobile as it comes to a stop.

5 a) Two forces, one 500 N and the other P applied by cables on each
side of the obstruction A in order to remove the spike. Write a
MATLAB program to determine:
(a) the magnitude of P necessary to such that the resultant T is
directed along the spike
(b) the magnitude of T
(c) plot P and T as a function of d. (Range of d between 1 and 20
mm).

b) The two cables MO and NO tied together at O and the loadings are
also shown. The magnitude of F is 150 N.

(a) Derive the expressions relating the tension in each cable as a


function of α.
(b) Write a MATLAB program to plot the tension in each cable for
0°  α 90º.
(c) Determine the smallest value of α for which both cables are in
tension.

c) The position x as a function of time of a particle that moves along a


straight line is given by x (t) = 0.5t3 – 2.5t2 – 6t +15
(a) Derive expressions for the velocity and acceleration of the
particle.
(b) Write a MATLAB program to plot the position, velocity and
acceleration as a function of time for 0t10 seconds.
6 a) If B (2, 3) is rotated in the clockwise direction by 90 degrees, Write
a MATLAB CODE to find the coordinate values?
b) If C (5, 2, 6) is rotated in the counterclockwise direction by 180
degrees about the x-axis, Write a MATLAB CODE to find the
coordinate values?
c) Write a MATLAB code to find the Moment of force with the force
5i+j-3k and position 2i+3j+4k.
7 a) Find the position vector and write a MATLAB code to find the
Moment of Force about point O.

b) Write a MATLAB coding to find the Circular motion of an


object moving in the radius 5 m with angular velocity 2
rad/s.
c) Write a MATLAB code to find the moment of force about point O.
8 a) Construct the simple pendulum model using Simscape.

Week No. Expt. No. Experiment Name


1 a) To Know the history and features of MATLAB

This chapter is a brief introduction to MATLAB (an abbreviation of MATrix LABoratory)


basics, registered trademark of computer software, version 4.0 or later developed by the Math
Works Inc. The software is widely used in many of science and engineering fields. MATLAB
is an interactive program for numerical computation and data visualization. MATLAB is
supported on Unix, Macintosh and Windows environments.

For more information on MATLAB, contact The MathWorks.Com. A Windows version of


MATLAB is assumed here. The syntax is very similar for the DOS version. MATLAB
integrates mathematical computing, visualization, and a powerful language to provide a
flexible environment for technical computing. The open architecture makes it easy to use
MATLAB and its companion products to explore data, create algorithms and create custom
tools, that provide early insights and competitive advantages.

Known for its highly optimized matrix and vector calculations, MATLAB offers an intuitive
language for expressing problems and their solutions both mathematically and visually.
Typical uses include:

• Numeric computation and algorithm development.

• Symbolic computation (with the built-in Symbolic Math functions).

• Modeling, simulation and prototyping.

• Data analysis and signal processing.

• Engineering graphics and scientific visualization.

Week No. Expt. No. Experiment Name


1 b) To Know the local environment of MATLAB

MATLAB Environment:
Matlab environment is an interactive platform, where you can write and run your Matlab
codes, and even can plot them. It allows you to do statistical calculations as well as visualize
them too. Matlab has a wide range of tools, that might be used for writing codes, plotting
graphs, and solving many complex equations

Workspace

Week No. Expt. No. Experiment Name


2 a) Write a MATLAB code to find V according to the given formula,
P*V = n*R*T, the variables are given as P=10, n=2, R=7, and T= ½.

Solution: The following code can be used to find the V value.


>> P=10;
n=2;
R=7;
T=1/2;
V=(n*R*T)/P
Output:
V=
0.7000
Week No. Expt. No. Experiment Name
2 b) Write a MATLAB code to plot the function y=2sinx.

Solution: The following code can be used to plot

>> x=linspace(0,pi,100);
y=2.*sin(x);
plot(x,y)

Output:

Week No. Expt. No. Experiment Name


2 c) Write a MATLAB code to plot the function y = sinx with grids.
Then, keep the first graph and plot a second function given by y =
cos (x) within the same interval. Insert the labels for each data set,
as well.

Code:
% Define the x-axis range
x = linspace(0, 2*pi, 100);

% Calculate the y-values for sin(x)


y1 = sin(x);

% Plot the first function with grid


plot(x, y1, 'b-', 'LineWidth', 2);
grid on;
xlabel('x');
ylabel('sin(x)');
title('Sine and Cosine Functions');
hold on;
% Hold the current plot

% Calculate the y-values for cos(x)


y2 = cos(x);

% Plot the second function on the same graph


plot(x, y2, 'r--', 'LineWidth', 2);
legend('sin(x)', 'cos(x)'); % Add a legend

Output:
Week No. Expt. No. Experiment Name
3 a) Write a MATLAB code to plot the three functions sinx, cosx and
sinx+cosx on different axes on the same figure using the subplot
command.

Code:
% Define the x-axis range
x = linspace(0, 2*pi, 100);
% Calculate the y-values for sin(x), cos(x), and sin(x) + cos(x)
y1 = sin(x);
y2 = cos(x);
y3 = sin(x) + cos(x);

% Create a figure with 3 subplots


figure;

% Subplot 1: sin(x)
subplot(3,1,1);
plot(x, y1, 'b-', 'LineWidth', 2);
grid on;
xlabel('x');
ylabel('sin(x)');
title('Sine Function');

% Subplot 2: cos(x)
subplot(3,1,2);
plot(x, y2, 'r--', 'LineWidth', 2);
grid on;
xlabel('x');
ylabel('cos(x)');
title('Cosine Function');

% Subplot 3: sin(x) + cos(x)


subplot(3,1,3);
plot(x, y3, 'g-', 'LineWidth', 2);
grid on;
xlabel('x');
ylabel('sin(x) + cos(x)');
title('Sum of Sine and Cosine Functions');

Output:

B) Generate the MATLAB code to calculate the area and perimeter of a circle,
where the radius is entered by the user.

Code:
% Get the radius from the user
radius = input('Enter the radius of the circle: ');

% Calculate the area and perimeter


area = pi * radius^2;
perimeter = 2 * pi * radius;

% Display the results


fprintf('Area of the circle: %.2f\n', area);
fprintf('Perimeter of the circle: %.2f\n', perimeter);

Output:
Enter the radius of the circle:
12
Area of the circle: 452.39
Perimeter of the circle: 75.40

C) Write a MATLAB code to find the first order and second order derivative of the
given function f=x3-7x2+6x-61.

Code:
% Define the function
syms x
f = x^3 - 7*x^2 + 6*x - 61;

% Calculate the first derivative


df = diff(f);

% Calculate the second derivative


d2f = diff(df);

% Display the results


disp('First derivative:');
disp(df);

disp('Second derivative:');
disp(d2f);

Output:
First derivative:
3*x^2 - 14*x + 6
Second derivative:
6*x - 14

4 Write a MATLAB program to plot the position, velocity and


acceleration as a function of time for a particle moves along a
straight line is given by the position relation, x=t3-6t2-15t+40.
Code:
% Define the time interval
t = linspace(0, 5, 100);

% Calculate the position, velocity, and acceleration


x = t.^3 - 6*t.^2 - 15*t + 40;
v = 3*t.^2 - 12*t - 15;
a = 6*t - 12;

% Create a figure with 3 subplots


figure;

% Subplot 1: Position vs Time


subplot(3,1,1);
plot(t, x, 'b-', 'LineWidth', 2);
grid on;
xlabel('Time (s)');
ylabel('Position (m)');
title('Position vs Time');

% Subplot 2: Velocity vs Time


subplot(3,1,2);
plot(t, v, 'r--', 'LineWidth', 2);
grid on;
xlabel('Time (s)');
ylabel('Velocity (m/s)');
title('Velocity vs Time');

% Subplot 3: Acceleration vs Time


subplot(3,1,3);
plot(t, a, 'g-', 'LineWidth', 2);
grid on;
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration vs Time');

Output:

B) The motion of a particle is defined by the relation x=6t 4-2t3-12t2+3t+3, where x


and t are expressed in meters and seconds, respectively. Write a MATLAB
program to determine the time, the position, and the velocity when a=0.
Code:

% Define the position function

syms t

x = 6*t^4 - 2*t^3 - 12*t^2 + 3*t + 3;

% Calculate the velocity and acceleration functions

v = diff(x, t);

a = diff(v, t);

% Find the time when acceleration is zero

t_zero_acc = solve(a == 0);

% Calculate the position and velocity at those times

x_zero_acc = subs(x, t, t_zero_acc);

v_zero_acc = subs(v, t, t_zero_acc);

% Display the results

disp('Time when acceleration is zero:');

disp(t_zero_acc);

disp('Position at those times:');

disp(x_zero_acc);

disp('Velocity at those times:');

disp(v_zero_acc);

Output:

Time when acceleration is zero:


1/2

2/3

Position at those times:

7/8

7/27

Velocity at those times:

21/2

77/9

C) An automobile weighing 4000 lb is driven down a 5° incline at a speed of 60


mi/h when the brakes are applied, causing a constant total braking force
(applied by the road on the tires) of 1500 lb. Write a MATLAB program to
determine the distance traveled by the automobile as it comes to a stop.

Code:

% Given parameters

weight = 4000; % lb

theta = 5; % degrees

v0 = 60; % mi/h

F_brake = 1500; % lb

% Convert units

g = 32.2; % ft/s^2

v0 = v0 * 5280/3600; % ft/s

% Calculate the acceleration due to gravity along the incline

a_gravity = g * sin(deg2rad(theta));

% Calculate the total deceleration

a_total = (F_brake - weight * sin(deg2rad(theta))) / (weight/g);

% Calculate the stopping distance using the kinematic equation


distance = (v0^2) / (2 * abs(a_total));

% Display the result

fprintf('The stopping distance is %.2f ft\n', distance);

Output:

The stopping distance is 417.76 ft

5 a) Two forces, one 500 N and the other P applied by cables on each
side of the obstruction A in order to remove the spike. Write a
MATLAB program to determine:
(a) the magnitude of P necessary to such that the resultant T is
directed along the spike
(b) the magnitude of T
(c) plot P and T as a function of d. (Range of d between 1 and 20
mm).

Code:

% Range of d

d = 1:1:20;

% Define alpha

alpha = atan(5./d);

% Define beta

beta = atan(7./d);

% Compute force P

P = 500 * sin(beta) ./ sin(alpha);

% Define force T

T = 500 * (sin(beta) .* cot(alpha) + cos(beta));

% Plot the forces

plot(d, P, '-*', d, T, '-p')


xlabel('d (mm)');

ylabel('Force (N)');

legend('Force P', 'Net force T');

grid on;

Output:

b) The two cables MO and NO tied together at O and the loadings are also shown.
The magnitude of F is 150 N.

(a) Derive the expressions relating the tension in each cable as a function of α.
(b) Write a MATLAB program to plot the tension in each cable for 0°  α
90º.
(c) Determine the smallest value of α for which both cables are in tension.
Code:

Alpha = 0:2:90;

alpha = Alpha * pi / 180;

fon = 150 - 200 * cos(alpha) + 115.47 * sin(alpha);

fom = -150 + 115.47 * sin(alpha) + 200 * cos(alpha);

ton = abs(fon);

tom = abs(fom);

[ton_min, i] = min(ton);

[tom_min, j] = min(tom);

Ang1_min = Alpha(i);

Ang2_min = Alpha(j);

plot(Alpha, fon, Alpha, fom);

legend('fon', 'fom');

xlabel('Alpha (degree)');

ylabel('Cable tension (N)');

grid on;

fprintf('(c)\n');

fprintf('Smallest value of Alpha for which the tensions are positive

is from %g to %g degrees\n', Ang1_min, Ang2_min)

Output:
c) The position x as a function of time of a particle that moves along a straight
line is given by x (t) = 0.5t3 – 2.5t2 – 6t +15
(a) Derive expressions for the velocity and acceleration of the particle.
(b) Write a MATLAB program to plot the position, velocity and acceleration as
a function of time for 0t10 seconds.

Code:

t=1:1:10;

x = 0.5*t.^3-2.5*t.^2-6*t+15;

v=diff(x);

a=diff(v);

plot(t,x,’-o’,’MarkerIndices’,1:5:length(x))

xlabel(‘time(s)’)

ylabel(‘position(x)’)grid on;

plot(t,v,’-o’,’MarkerIndices’,1:5:length(v))

xlabel(‘time(s)’)

ylabel(‘velocity(v)’)
grid on;

Output:

6 A) If B (2, 3) is rotated in the clockwise direction by 90 degrees, Write


a MATLAB CODE to find the coordinate values?
B) If C (5, 2, 6) is rotated in the counterclockwise direction by 180
degrees about the x-axis, Write a MATLAB CODE to find the
coordinate values?
C) Write a MATLAB code to find the Moment of force with the force
5i+j-3k and position 2i+3j+4k.

A) Code:

B=[2,3];
theta=90;
R=[cosd(-theta) -sind(-theta); sind(-theta) cosd(-theta)];
C=B*R
disp('The result of the matrix rotation is:');
disp(C);
OUTPUT:
C=
-3 2
The result of the matrix rotation is:
-3 2

B)
Code:
C=[5,2,6];
theta=180;
R=[1,0,0;0 cosd(-theta) -sind(-theta); 0 sind(-theta) cosd(-theta)];C=B*R
disp('The result of the matrix rotation is:');
disp(C);
OUTPUT:
F=
526
H=
100
0 -1 0
0 0 -1
D=
5 -2 -6
the result of matrix rotation is:
5 -2 -6

C)
Code:
r=[2;3;4];
F=[5;1;-3];
M=cross(r,F);
disp('Moment of force(Torque):');
disp(M);
OUTPUT:
Moment of force(Torque):
-13
26
-13

7 A) Find the position vector and write a MATLAB code to find the
Moment of Force about point O.
Code:
r=[3,3,1.5];
F=[-6,3,10];
M=cross(r,F);
disp('the moment of force about point O is:');
disp(M);
OUTPUT:
the moment of force about point O is:
25.5000 -39.0000 27.0000

B) Write a MATLAB coding to find the Circular motion of an object


moving in the radius 5 m with angular velocity 2 rad/s.

radius=5;
angular_velocity=2;
t=linspace(0,10,100);
x=radius*cos(angular_velocity*t);
y=radius*sin(angular_velocity*t);
figure;
plot(x,y);
xlabel('X(m)');
ylabel('Y(m)');title('Circular motion');
axis equal;
grid on;
OUTPUT:

C) Write a MATLAB code to find the moment of force about point O.

Code:

r = [ 4, 5, 3];
F = [ 100, -120, 75];
M = cross(r,F);
disp('moment of force(torque) at the origin is:');disp(M);

OUTPUT:
moment of force(torque) at the origin is:
735 0 -980

8 b) Construct the simple pendulum model using Simscape.

Arrangement:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy