KABALAJI

 avatar
unknown
matlab
2 years ago
3.6 kB
4
Indexable
% TANGENT
clc
clear all 
close all
syms x 
y=input('enter the function in terms of x:')
x1=input('enter the tangent value:')
ezplot(y,[x1-2,x1+2])
hold on 
yx=diff(y,x)
slope=subs(yx,x,x1)
y1=subs(y,x,x1)
plot(x1,y1)
tangent_line=slope*(x-x1)+y1
h=ezplot(tangent_line,[x1-2,x1+2])
set(h,'color','r*')

%%
%EXTREMA 
clc 
clear all
close all
syms x real
y=input('enter the function:')
yx=diff(y,x)
c=solve(yx)
cmin=min(double(c))
cmax=max(double(c))
ezplot(y,[cmin-2,cmax+2])
hold on 
yxx=diff(yx,x)
for i =1:1:size(c)
    T1=subs(yxx,x,c(i))
    T2=subs(y,x,c(i))
if (double(T1)==0)
    sprintf('It has a point of inflexion is %d',double(c(i)))
else
    if(double(T1)<0)
        sprintf('The maximum value of function is %d',double(c(i)))
        sprintf('The value of function is %d',double(T2))
    else
        sprintf('The minimum value of the function is %d',double(c(i)))
        sprintf('The value of the function is %d',double(T2))
    end
end
plot(double(c(i)),double(T2),'r*','markersize',20)
end 
%% INTEGRALS
clc
clear all
format compact
syms x
f=input('enter a function f(x):')
a=input('enter the lower limit:')
b=input('enter the upper limit:')
n=input('enter the number of intervals:')
value=0
dx=(b-a)/n
for k=1:n
c=a+k*dx
d=subs(f,x,c)
values=value+d
end
value=dx*value
z=int(f,a,b)
ezplot(f,[a b])
figure
rsums(f,a,b)

%% AREA UNDER CURVES
clc
clear all
format compact
syms x
y1=input('enter the upper curve as a function of x :')
y2=input('enter the lower curve as a function of x :')
t=solve(y1,-y2)
t=double(t)
A=int(y1-y2,t(1),t(2))
D=[t(1)-0.2 t(2)+0.2];
ezl=ezplot(y1,D);
set(ezl,'color','r')
hold on
ez2=ezplot(y2,D);
set(ez2,'color','g')
xv=linspace(t(1),t(2))
y1v=subs(y1,x,xv);
y2v=subs(y2,x,xv);
x=[xv,xv];
y=[y1v,y2v];
fill(x,y,'b')
%% LAGRANGE
clc
clear all
format compact
syms x y lam real
f=input('enter the function f(x,y)');
g=input('enter constraint g(x,y)');
F=f-lam*g;
Fd=jacobian(F, [x y lam])
[ax,ay,alam]=solve(Fd,x,y,lam)
ax=double(ax)
ay=double(ay)
T=subs(f,{x,y},{ax,ay})
T=double(T)
epx=3
epy=3
for i=1 :length(T)
figure
D=[ax(i)-epx ax(i)+epx ay(i)-epy ay(i)+epy]
fprintf('the critical point (x,y) is (%1.3f, %1.3f).',ax(i),ay(i))
fprintf('the value of the function is %1.3f\n',T(i))
ezcontour(f,D,300)
hold on
h=ezplot(g,D)
set(h,'color',[1.0,0.7,0.9])
plot(ax(i),ay(i),'k.','markersize',40)
end
TT=sort(T);
f_min=TT(1)
f_max=TT(end)
%% VOLUME UNDER SURFAACES
clc
clear all 
format compact 
syms x y z
Ivalue=int(int((x+y)/4,y,x/2,x),x,1,2)
viewSolid(z,0+0*x+0*y,(x+y)/4,y,x/2,x,x,1,2)
%% CURL D AND G 
clc
clear all
format compact
syms x y
f=input('Enter the function f(x,y): ')
grad=gradient(f,[x,y])
P(x,y)=grad(1)
Q(x,y)=grad(2)
x=linspace(-2,2,10);
y=x;
[X,Y]=meshgrid(x,y)
U=P(X,Y);
V=Q(X,Y);
quiver(X,Y,U,V,1)
axis on
xlabel ('x');
ylabel('y')
hold on
fcontour(f,[-2,2])
%% GREENS THEOREM
clc
clear all
format compact
syms x y t
F=input('Enter the vector function M(x,y)i+N(x,y)j in the form [M N]: ')
M(x,y)=F(1);
N(x,y)=F(2);
r=input('Enter the parametric form of the curve C as[r1(t) r2(t)]:' )
r1=r(1);
r2=r(2);
P=M(r1,r2);
Q=N(r1,r2);
dr=diff(r,t);
F1=sum([P,Q].*dr)
T=input('Enter the limits of integration for t [t1, t2]:' )
t1=T(1);
t2=T(2);
LHS=int(F1,t,t1,t2)
yL=input('Enter the limits for y in terms of X:[y1,y2]:' )
xL=input('Enter the limits for x :[x1,x2]: ')
y1=yL(1);
y2=yL(2);
x1=xL(1);
x2=xL(2);
F2=diff(N,x)-diff(M,y)
RHS=int(int(F2,y,y1,y2),x,x1,x2)
if(LHS==RHS)
disp('LHS of greens theorem')
disp(LHS)
disp('RHS of greens theorem')
disp(RHS)
disp('Hence, Greens theorem is verified.')
end
Editor is loading...