Lab Assignment - 1: Name: Savio K Santhosh Reg No: 21BRS1273
Lab Assignment - 1: Name: Savio K Santhosh Reg No: 21BRS1273
Lab Assignment –1
1.
Aim: To plot the functions f(x) = x + sin x and g(x)= x+ cos x for x ∈ [0, 2π], in the same figure.
Label your x and y axes and add a title to your plot and also add different colours, line styles
and markers.
MATLAB Code:
clc
clear all
x=linspace(0,2*pi,25);
y1=x+sin(x);
plot(x,y1,'g:*')
xlabel('x-axis')
ylabel('y-axis')
title('f(x)+g(x)')
hold on
y2=x+cos(x);
plot(x,y2,'b--o')
hold off
Result:
Program successfully executed.
2.
Aim: Plot the function x2 + 8x + 72 in the interval [-10 10] using ezplot and Label your x and y
axes and add a title to your plot.
MATLAB Code:
clc
clear all
ezplot('x^2+8*x+72',[-10 10])
xlabel('x-axis')
ylabel('y-axis')
title('x^2 + 8x + 72')
Graph:
Result:
Program successfully executed.
3.
Aim: Find the derivative of the curve y = x3 - 3x2 + 10 at x = 3.
MATLAB Code:
clc
clear all
syms x real
y=x^3-3*x^2+10;
fx=diff(y);
c=eval(subs(fx,x,3));
fprintf('Derivative of function is: ')
disp(fx)
Result:
Program successfully executed.
4.
Aim: Integrate the function x3 + 8x2 - 4x + 42 with lower limit 1 and upper limit 5.
MATLAB Code:
clc
clear all
syms x real
y=x^3+8*x^2-4*x+42;
f1=int(y,x);
c=eval(subs(f1,x,1));
d=eval(subs(f1,x,5));
fprintf("Integral of function is:")
disp(f1)
fprintf("Integral of function with limits 1-5 is:")
disp(d-c)
Result:
Program successfully executed.