Assignment 1 Solution (Redo) by Fahezun
Assignment 1 Solution (Redo) by Fahezun
Question 1 ......................................................................................................................... 1
a(i) .................................................................................................................................... 1
a(ii) ................................................................................................................................... 2
a(iii) .................................................................................................................................. 3
b ....................................................................................................................................... 5
c(i) .................................................................................................................................... 6
c(ii) ................................................................................................................................... 6
Question 2 ......................................................................................................................... 7
a(i) .................................................................................................................................... 7
a(ii) ................................................................................................................................... 8
a(iii) .................................................................................................................................. 9
b(i) .................................................................................................................................. 10
b(ii) ................................................................................................................................. 11
c ..................................................................................................................................... 12
Question 3 ........................................................................................................................ 14
i ...................................................................................................................................... 14
ii ..................................................................................................................................... 16
Question 1
a(i)
clc,clear all,close all
syms x
f = sin(1/x);
fplot(f,'linewidth',3)
axis([-1.5 1.5 -1.5 1.5])
grid on
line([-10,10],[0,0],'color','k')
line([0,0],[-10,10],'color','k')
lhl=limit(f,x,0,'left')
rhl=limit(f,x,0,'right')
if lhl==rhl
disp('limit exist')
else
disp('limit doen''t exist')
end
lhl =
1
NaN
rhl =
NaN
a(ii)
clc,clear all,close all
syms x
f = 1/(1+exp(1/x));
pretty(f)%to check with the actual mathematical expression
fplot(f,'linewidth',1)
axis([-5 5 -0.1 1.1])
grid on
line([-10,10],[0,0],'color','k')
line([0,0],[-10,10],'color','k')
lhl=limit(f,x,0,'left')
rhl=limit(f,x,0,'right')
2
if lhl==rhl
disp('limit exist')
else
disp('limt doesn''t exist')
end
1
------------
exp(1/x) + 1
lhl =
rhl =
a(iii)
clc,clear all,close all
3
syms x
f=(exp(x^3)-1)/(1-cos(sqrt(x-sin(x))))
pretty(f)
fplot(f,'linewidth',2)
axis([-5 5 -1 20])
lhl=limit(f,x,0,'left')
rhl=limit(f,x,0,'right')
line([-10,10],[0,0],'color','k')
line([0,0],[-10,25],'color','k')
if lhl==rhl
disp('limit exist')
else
disp('limt doesn''t exist')
end
hold on
plot(0,rhl,'bo','markersize',5,'markerfacecolor','r')
f =
3
exp(x ) - 1
- -------------------------
cos(sqrt(x - sin(x))) - 1
lhl =
12
rhl =
12
limit exist
4
b
clc,clear all,close all
syms x
fplot(((x^2)-x)/((x^2)-1),[-5 5],'b')
hold on
plot(1,1,'bo','markersize',3,'markerfacecolor','b')
axis([-5 5 -5 5])
grid on
5
c(i)
clc,clear all,close all
syms x a b
limit(sqrt(x^2 +a*x)-sqrt(x^2+b*x),x,inf)
ans =
a/2 - b/2
c(ii)
syms x
limit(sqrt(9*x^2 + x)-3*x,x,inf)
ans =
1/6
6
Question 2
a(i)
clc,clear all,close all
syms q
f =((q^2 + 3)*(q^4 - 1))/(12*q^4)
f1 = simplify(diff(f,q,1))
f2 = simplify(diff(f,q,2))
fplot([f,f1,f2])
axis([-5 5 -5 5])
grid on
legend('f','f1','f2')
line([-10,10],[0,0],'color','k')
line([0,0],[-10,10],'color','k')
f =
f1 =
f2 =
7
a(ii)
clc,clear all,close all
syms x
f = 2*x - 5*x^(3/4)
f1 =diff(f,x,1)
f2 =diff(f,x,2)
fplot([f,f1,f2])
axis([-45 45 -10 10])
grid on
legend('f','f1','f2')
line([-45,45],[0,0],'color','k')
line([0,0],[-10,10],'color','k')
f =
2*x - 5*x^(3/4)
f1 =
2 - 15/(4*x^(1/4))
8
f2 =
15/(16*x^(5/4))
a(iii)
clc,clear all,close all
syms x
f = exp(x)-x^3;
f1 = diff(f,x,1);
f2 =diff(f,x,2);
fplot([f f1 f2],'linewidth',1.5)
axis([-10 10 -10 10])
grid on
legend('f','f1','f2')
line([-10,10],[0,0],'color','k')
line([0,0],[-10,10],'color','k')
9
b(i)
clc,clear all, close all
syms x
f(x) = sqrt(x);
a=0; b=4;
f1(x)= diff(f,x);
sol=solve(f1==(f(b)-f(a))/(b-a),x);%applying the condition of MVT
t(x)=f(sol)+f1(sol)*(x-sol); % y-y1=m(x-x1)
s(x)=f(a)+((f(b)-f(a))/(b-a))*(x-a); % y-y1/y1-y2=x-x1/x1-x2
fplot(f,[0 4],'linewidth',1.5)
hold on
fplot(t,[0 4],'linewidth',1.5)
hold on
fplot(s,[0 4],'linewidth',1.5)
legend('function','tangent','secant','location','best')
hold on
plot(a,f(a),'o','markersize',5,'markerfacecolor','b')
hold on
plot(b,f(b),'o','markersize',5,'markerfacecolor','b')
hold on
plot(sol,f(sol),'o','markersize',5,'markerfacecolor','y')
10
if f1(sol)==(f(b)-f(a))/(b-a)
fprintf('tangent and secant are parallel')
else
fprintf('not parallel')
end
b(ii)
clc,clear all,close all
syms x
f(x)= 3+2*x-x^2;
a=0;b=1;
f1(x)=diff(f,x);
sol=solve(f1==((f(b)-f(a))/(b-a)),x);
t(x)=f(sol)+f1(sol)*(x-sol);
s(x)=f(a)+((f(b)-f(a))/(b-a))*(x-a);
fplot(f,[0 1],'linewidth',1.5)
hold on
fplot(t,[0 1],'linewidth',1.5)
hold on
fplot(s,[0 1],'linewidth',1.5)
11
hold on
plot(a,f(a),'o','markersize',5,'markerfacecolor','b')
hold on
plot(b,f(b),'o','markersize',5,'markerfacecolor','b')
hold on
plot(sol,f(sol),'o','markersize',5,'markerfacecolor','y')
if f1(sol)==(f(b)-f(a))/(b-a)
fprintf('tangent and secant line are parallel')
else
fprintf('not parallel')
end
c
clc,clear all,close all
syms x
f(x)= 36*x + 3*x^2 - 2*x^3;
f1=diff(f,x,1);
f2=diff(f,x,2);
fplot(f,[-6 7],'linewidth',1.5)
hold on
12
fplot(f1,[-6 7],'linewidth',1.5)
hold on
fplot(f2,[-6 7],'linewidth',1.5)
%i
s1=solve(f1>0,'returnconditions',true,'real',true);
%s1=solve(f1>0) won't do any good
increasing_int = s1.conditions
s2=solve(f1<0,'returnconditions',true);
decreasing_int = s2.conditions
%iii
s4=solve(f2>0,'returnconditions',true);
con_up_int=s4.conditions
s5=solve(f2<0,'returnconditions',true);
con_up_int=s5.conditions
s6=solve(f2==0,'real',true)
%or,solve(f2==0,x)
hold on
plot(s3,f(s3),'ko','markersize',5,'markerfacecolor','m')
plot(s6,f(s6),'ko','markersize',5,'markerfacecolor','k')
legend('f','f1','f2','sationary-pt','inflection-pt')
increasing_int =
decreasing_int =
3 < x
x < -2
s3 =
-2
3
con_up_int =
x < 1/2
13
con_up_int =
1/2 < x
s6 =
1/2
Question 3
i
clc,clear all,close all
syms x
s=solve(sqrt(x-1) == x-1,x);
x = linspace(s(1),s(2),100);
%basically linspace(1,2,100)
y1=sqrt(x-1);
y2=x-1;
14
plot(x,y1,'r','linewidth',2);
hold on
plot(x,y2,'b','linewidth',2);
%[x fliplr(x)] creates an array that starts with the x-values from
left
%to right(from 1 to 2) and then appends the reversed x-values(from 2
to 1)
%In [y1 filplr(y2)],y1=sqrt(x-1) represents the y-values of the top
curve
%and y2=x-1 represents y-values for the bottom curve.
%[y1 filplr(y2)] creates an array that starts with the y-values of the
top
%curve(i.e y1) and then appends the reversed y-values of the bottom
curve
%(i.e y2),this completes the boundary of the region
grid on
legend('y=sqrt(x-1)','y=x-1','enclosed region','location','best')
%why 'location','best'?
%area
clear x
syms x
y1=sqrt(x-1);
y2=x-1;
a=int(y1-y2,x,s(1),s(2));
fprintf('The area of enclosed region is :%f',a)
15
ii
clc,close all,clear all
x=linspace(0,pi,100);
y1=cos(x);
y2=1-cos(x);
plot(x,y1,'r','linewidth',2)
hold on
plot(x,y2,'k','linewidth',2)
%area
clear x
syms x
y1=cos(x);
y2=1-cos(x);
s=solve(y1==y2,x);
area=int(y1-y2,x,0,s(2))+int(y2-y1,x,s(2),pi)
fprintf('The area of enclosed region is :%f',area)
16
area =
pi/3 + 2*3^(1/2)
17