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

Exercise 1:: Solution: Code

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 7

Exercise 1: Use MATLAB to generate the first 100 terms in the sequence a (n) define recursively by

(𝑛 + 1) = 𝑝 ∗ (𝑛) ∗ (1 − (𝑛)) with p=2.9 and a(1) = 0.5

Solution:
Code:
p=2.9;
a(1)=0.5;
for n=1:100
a(n+1)=p*a(n)*(1-a(n))
end

Result:
Solution:
Code:
for Tc=0:10:200
Tf=9/5*Tc+32
end

Result:
Exercise 2:
MATLAB M-file Function
Consider the following equation (𝑡)=𝑦(0)√1−𝜁𝑒−𝜁𝜔𝑛𝑡sin⁡(𝜔𝑛√1−𝜁2∗𝑡+𝜃)
a) Write a MATLAB M-file function to obtain numerical values of y(t). Your function
must take (0), 𝜁, 𝜔𝑛, t and 𝜃 as function inputs and (𝑡) as output argument.
b) Obtain the plot for y(t) for 0<t<10 with an increment of 0.1, by considering the
following two cases

Case 1: (0)=0.15 m, 𝜔𝑛⁡=⁡√2 rad/sec, 𝜁⁡=⁡3/(2√2􁈻) and 𝜃⁡=⁡0;


Case 2: (0)=0.15 m, 𝜔𝑛⁡=⁡√2 rad/sec, 𝜁⁡=⁡1/(2√2􁈻) and 𝜃⁡=⁡0;

Code:

%Lab #1

%MatLab M-file Function Exersice

%{

This program will ask users to input values for the following equation

y(t)=(y0/(sqrt(1-tao)))*exp(-tao*omegaN*t)*sin(omegaN*(sqrt(1-(tao^2))*t +

angleTeta));

%}

y0=input('Please enter the value of y0: ');

tao=input('Please enter the value of tao: ');

omegaN=input('Please enter the value of omega (in rad per second): ');

angleTeta=input('Please enter the value of teta: ');

t=input('Please input the value of ''t'' to evaluate the function y(t): ');

y_t=(y0/(sqrt(1-tao)))*exp(-tao*omegaN*t)*sin(omegaN*(sqrt(1-(tao^2))*t +
angleTeta));

disp(y_t);

matlab output part a:

The above output demonstrate that Mat Lab can be use to obtain numerical values of
an equation such as (𝑡)=𝑦(0)√1−𝜁𝑒−𝜁𝜔𝑛𝑡sin⁡(𝜔𝑛√1−𝜁2∗𝑡+𝜃)
Evaluated at the users specified values.

Graph plot part b:


The above graph represents the output plot of the equation

y(t) = 𝑦(0)√1−𝜁𝑒−𝜁𝜔𝑛𝑡sin⁡(𝜔𝑛√1−𝜁2∗𝑡+𝜃)

With the conditions of y0=0.15 m, ωn = √ rad/sec, ζ = 3/(2√ ) and θ = 0

Exercise 4:
Plot the function
                        Y(x)=exp(-x)sin(8x)  for  0<=x<=2π
Solution:
Code:
 Function y = func(x)                          % function decleration

Y=exp(-x)*sin(8*x);

 Command window .

I=1;                                        

X=0;

While(x<=(2*pi))

Y(i)=func(x);

I=i+1;

X=x+0.1;

End

Plot(y)
Screen shots:
Graph plot screenshot:

You might also like