Matlab Assignment 23mic7015
Matlab Assignment 23mic7015
ASSIGNMENT
MAT1008
SLOT: L47+48
x2=0:1:5;
y2=5+x2.^4;
subplot(2,2,2)
plot(x2,y2,':')
title('Second curve')
x3=-2*pi:pi/100:2*pi;
y3=sin(x3);
subplot(2,2,3)
plot(x3,y3,'-.')
title('Third curve')
x4=-4*pi:pi/100:4*pi;
y4=sin(x4)+cos(x4);
subplot(2,2,4)
plot(x4,y4,'o')
title('Fourth curve')
Output:
2)Draw the surface of f = x3cosy + x2exp(y) ; x ϵ [-2,2] , y ϵ [-4,4].
Solution:
x=linspace(-2,2);
y=linspace(-4,4);
[x,y]=meshgrid(x,y);
f=x^3*cos(y)+x^2*exp(y);
surf(x,y,f)
Output:
3) Find the extreme values of the functions:
(i) f(x)= x3+x2-8x+5
Solution:
syms x real
y = x.^3+x.^2-8*x+5;
yx = diff(y,x)
c = solve(yx)
cmin = min(double(c));
cmax = max(double(c));
figure(1)
ezplot(y,[cmin-2,cmax+2])
hold on
yxx = diff(yx,x)
for i = 1:length(c)
T1 = subs(yxx, x,c(i));
T3= subs(y, x, c(i));
if (double(T1)==0)
sprinty('The test fails at x=%d',double (c(i)))
elseif (double(T1) < 0)
sprintf('The local maximum point x is %d', double(c(i)))
sprintf('The local maximum value of the function is %d', double (T3))
else
sprintf('The local minimum point x%d', double(c(i)))
sprintf('The local minimum value of the function is %d', double (T3))
% end
end
plot(double(c(i)), double(T3), 'r*');
end
Output:
(ii) f(x)= x/x2+1
Solution:
syms x real
y = x/((x^2)+2);
yx = diff(y,x)
c = solve(yx)
cmin = min(double(c));
cmax = max(double(c));
figure(1)
ezplot(y,[cmin-2,cmax+2])
hold on
yxx = diff(yx,x)
for i = 1:length(c)
T1 = subs(yxx, x,c(i));
T3= subs(y, x, c(i));
if (double(T1)==0)
sprinty('The test fails at x=%d',double (c(i)))
elseif (double(T1) < 0)
sprintf('The local maximum point x is %d', double(c(i)))
sprintf('The local maximum value of the function is %d', double (T3))
else
sprintf('The local minimum point x%d', double(c(i)))
sprintf('The local minimum value of the function is %d', double (T3))
% end
end
plot(double(c(i)), double(T3), 'r*');
end
Output: