Discussion:: Figure 1 Plot For y Exp (-2 T) . Cos (5 T)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Code

n=3;
p=power((1+2/(n*n)),n);
p
Output
-1.8258

n=7;
p=power ((1+2/(n*n)),n);
p
Output
1.3232
Discussion:
In this problem power function is used to solve the problem.

2. Plot the function: y = e-at*cos (ωt), for a = 2, ω= 5, and t = 0-10.

Code
t=[0:1:10];
y=exp(-2*t).*cos(5*t);
plot(t,y);
Output graph:-

Figure 1 Plot for y=exp(-2*t).*cos(5*t);


Discussion:
In this problem we used exponential function and cosine function and plot its graph using
plot function.

3. Try using the WHILE and the IF statements to calculate all the Fibonacci numbers so that
the sum of two consecutive numbers is smaller than 10,000. How many are even? How many
are Odd? Try to plot them.
Code
loop=1;
a=0; b=1;c=0,odd=0,even=0;
while((a+b)<=10000)
c=a+b;
a=b;
b=c;
if rem(b,2)==0
even=even+1;
else
odd=odd+1;
end
res(loop)=b;
loop=loop+1;
end
even=even+1
odd=odd+1
x=[1:1:length(res)]
plot(x,res);
Output Graph

Figure 2 Plot for fibonacci Series


Discussion
In this problem we used while loop for finding Fibonacci series and also used if else statement
to check the condition. Here we also used remainder(rem) function to find even and odd
number.

4. Given f(x)= (x2+2x+3)/(x+3).Plot f(x) for 0<=x<=100


Code
x=[0:1:100];
y=(x.*x+2*x+3)./(x+3);
plot(x,y);

Output graph:-

Figure 3plot for f(x)= (x2+2x+3)/(x+3).Plot f(x) for 0<=x<=100

Discussion
Here we plot the function y using plot function. The graph for is found nearly straight line
starting just above the origin.

Conclusion
In this lab we were familiarized with basic MATLAB function. We used some basic
function to plot graph of function. We were familiarized with control statement, loops,
plot function, as well as input vector matrices in MATLAB.

You might also like