0% found this document useful (0 votes)
73 views7 pages

Nitya Nand Jha 20BCY10163 Codes With Changed Values

The document contains MATLAB code for analyzing and plotting the solutions to different types of harmonic oscillator systems: underdamped, overdamped, critically damped, and driven. The code defines parameters, calculates relevant values like natural frequencies and decay constants, generates time and frequency arrays, computes the oscillator solutions, and plots the results with labels and legends.

Uploaded by

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

Nitya Nand Jha 20BCY10163 Codes With Changed Values

The document contains MATLAB code for analyzing and plotting the solutions to different types of harmonic oscillator systems: underdamped, overdamped, critically damped, and driven. The code defines parameters, calculates relevant values like natural frequencies and decay constants, generates time and frequency arrays, computes the oscillator solutions, and plots the results with labels and legends.

Uploaded by

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

NITYA NAND JHA

20BCY10163
CODES WITH
CHANGED VALUES
%under_damp.m

%plots the underdamped HO solution

clear;

m=0.05; %mass

k=5; %spring constant

c=0.08; %drag coefficient

x0=2.0; %initial position

v0=1.0; %initial speed

gam=c/2/m; %critical gamma

wo=sqrt(k/m); %SHO natural frequency

desc=wo^2-gam^2; %must be positive this time

if desc <= 0; %ensure appropriate problem conditions

disp('gam needs to be smaller');

return;

end

w=sqrt(desc); %underdamped frequency

B=sqrt(x0^2+(v0+gam*x0)^2/w^2); %constant B for underdamped

th=atan(w*x0/(v0+gam*x0)); %angle theta

tmax=10; %maximum time

NPTS=80; %number of points

t=[0:tmax/NPTS:tmax]; %time array

x=B*exp(-gam*t).*sin(w*t+th); %underdamped solution

xe=B*exp(-gam*t); %the decay envelope

plot(t,x,'b:',t,xe,'r-.');

title('Underdamped Harmonic Oscillator','FontSize',14)

ylabel('Underdamped, Decay Envelope','FontSize',14);

xlabel('t','FontSize',14);

1
h=legend('Underdamped','Decay Envelope'); set(h,'FontSize',14);

2
%over_crit_damp.m

%plots the overdamped and critically damped HO solutions

clear;

m=0.05; %mass

k=1; %spring constant

c=0.5; %drag coefficient

x0=1.0; %initial position

v0=5.0; %initial speed

gam=c/2/m; %critical gamma

desc=gam^2-k/m; %must be positive

if desc <= 0; %ensure appropriate problem conditions

disp('gam needs to be greater');

return;

end

gam1=gam+sqrt(desc); %overdapmed gamma1

gam2=gam-sqrt(desc); %overdapmed gamma2

Bo=(v0+gam1*x0)/(gam1-gam2); %constant B for overdamped

Ao=x0-Bo; %constant A for overdamped

Ac=x0; %constant A for critically damped

Bc=v0+gam*x0; %constant B for critically damped

tmax=4; %maximum time

NPTS=200; %number of points

t=[0:tmax/NPTS:tmax]; %time array

xo=Ao*exp(-gam1*t)+Bo*exp(-gam2*t); %overdamped

xc=Ac*exp(-gam*t)+Bc*t.*exp(-gam*t);%critically damped

plot(t,xo,'b:',t,xc,'r-.');

title('Overdamped and Critically Damped Comparison','FontSize',14)

1
ylabel('Xoverdamped, Xcritically-damped','FontSize',14);

xlabel('t','FontSize',14);

h=legend('Overdamped','Critically Damped'); set(h,'FontSize',14);

2
%drive_amp.m

%plots the amplitude of the solution for a driven HO

clear;

m=0.5; %mass

k=0.5; %spring constant

F0=0.5; %driving force amplitude

wo=sqrt(k/m); %SHO natural frequency

wmin=0.1; %minimum frequency

wmax=6; %maximum frequency

NPTS=50; %number of points

w=[wmin:wmax/NPTS:wmax]; %w array

hold on %get ready to superimpose plots

cmin=0.2; %minimum value of c

cmax=2*m*wo/sqrt(2); %maximum c so that om_res is real

cstep=(cmax-cmin)/5; %c step size

for c=cmin:cstep:cmax, %loop over the drag coefficient

gam=c/2/m; %find gamma

desc=(2*gam*w).^2+(wo^2-w.^2).^2;

A=F0/m./sqrt(desc); %The driven ho amplitude

plot(w,A); %plot amplitude

om_res=sqrt(wo^2-2*gam^2); %resonant frequency

Amax=F0/2/m/gam/sqrt(wo^2-gam^2); %Maximum amplitude at om_res

%next, draw point at position of Amax

line([om_res;om_res],[Amax;Amax],'Color','red','Marker','.');

%num2str(c,p) c to string with p digits

%cat(2,'a','b') concatenates a and b

str=cat(2,'\gamma=',num2str(gam,2));

1
text(om_res+0.1,Amax-0.06,str,'FontSize',10,'Color','red');

end

title('Amplitude versus Motor Frequency','FontSize',14)

ylabel('A(\omega_D)','FontSize',14);

xlabel('\omega_D','FontSize',14);

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