# Untitled

unknown
plain_text
2 years ago
6.5 kB
0
Indexable
Never
```# langraanges

clc
clear all
syms x y z L
f=x*x+y*y+z*z;
g=3*x*x+4*x*y+6*y*y-140;
F=f+L*g;
j=jacobian(F,[x y z]);
s=solve(g,j(1),j(2),j(3));
p=double([s.x,s.y,s.z]);
h1=p(:,1);
h2=p(:,2);
h3=p(:,3);
X=[h1];
Y=[h2];
Z=[h3];
st_pts=table([X,Y,Z])
[n,m]=size(st_pts);
for i=1:n
F(i)=subs(f,{x,y,z},{s.x(i),s.y(i),s.z(i)});
end
if n>1
F_max=max(F);
disp("f_max");
disp(F_max);
F_min=min(F);
disp("f_min")
disp(F_min);
end

clear
clc
syms x y
f=input('enter the function f(x,y) :' );
x=linspace(-2,2,10);
y=x;
[X,Y]=meshgrid(x,y);
hold on
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])

# line integral

clc
clear all
syms x y t
f=input("enter the function in form [x,y] ");
r=input("enter x,y in the form paramateric form");
g=input("enter limits of t");
a=g(1);
b=g(2);
dr=diff(r,t);
F=subs(f,{x,y},r);
Fdr=sum(F.*dr);
I=int(Fdr,t,a,b);
P(x,y)=f(1);
Q(x,y)=f(2);
x1=linspace(-2*pi,2*pi,10);
y1=x1;
[X,Y]=meshgrid(x1,y1);
U=P(X,Y);
V=Q(X,Y);
quiver(X,Y,U,V,1.5)
hold on
t1=linspace(0,2*pi);
x=subs(r(1),t1);
y=subs(r(2),t1);
plot(x,y,'r')

# greens

clear
clc
syms x y t
F=input("ENTER the vector function M(x,y)I+N(x,y) 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 lmits for y in terms of x: [y1,y2]:");
xL=input("enter the limits for x as constanasts : [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

# volume under the surfaces

syms x y z
int(int(function y),y1,y2),x,x1,x2)
viewSolid(z,z1,z2,y,y1,y2,x,x1,x2)

# To find the maxima and minima of the single variable function and visualize

clc
clear all
syms x real
f=9*x-6*x*x+x^3+1
fx= diff(f,x)
fxx= diff(fx,x)
c = solve(fx);
%z=size(c)
c=double(c);
for i = 1:length(c)
T1 = subs(fxx, x ,c(i));
T1=double(T1);
T3= subs(f, x, c(i));
T3=double(T3);
if (T1==0)
sprintf('The inflection point is x = d',c(i))
else
if (T1 < 0)
sprintf('The maximum point x is %d', c(i))
sprintf('The maximum value of the function is %d', T3)
else
sprintf('The minimum point x is %d', c(i))
sprintf('The minimum value of the function is %d', T3)
end
end
cmin = min(c);
cmax = max(c);
D = [cmin-2, cmax+2];
ezplot(f,D)
hold on
plot(c(i), T3, 'g*', 'markersize', 15);
end

# To find the area of the regions enclosed by curves and visualize it.

clc
clear all
syms x y real
y1=-x*x+4*x;
y2=x*x;
fg=figure;
ax=axes;
t=solve(y1-y2);
k=double(t)
n=length(k)
m1=min(k)
m2=max(k)
ez1=ezplot(y1,[m1-1,m2+1]);
hold on
ez2=ezplot(y2,[m1-1,m2+1]);
TA=0;

for i=1:n-1
A=int(y1-y2,t(i),t(i+1));
TA= TA+abs(A)
x1 = linspace(k(i),k(i+1));
yy1 =subs(y1,x,x1);
yy2 = subs(y2,x,x1);
x1 = [x1,fliplr(x1)];
yy = [yy1,fliplr(yy2)];
fill(x1,yy,'g')
grid on

# To find Maximum and Minimum values (Extreme values) of a function f (x, y) using
MATLAB.
clc
clear
syms x y
f(x,y)=2*(x^2-y^2)-x^4+y^4;
p=diff(f,x); q=diff(f,y);
[ax,ay]=solve(p,q);
ax=double(ax);ay=double(ay);
r=diff(p,x); s=diff(p,y); t=diff(q,y);D=r*t-s^2;
figure
fsurf(f);
legstr={'Function Plot'};% for Legend
for i=1:size(ax)
T1=D(ax(i),ay(i));
T2=r(ax(i),ay(i));
T3=f(ax(i),ay(i));
if(double(T1)==0)
sprintf('At (%f,%f) further investigation is required',ax(i),ay(i))
legstr=[legstr,{'Case of Further investigation'}];
mkr='ko';
elseif (double(T1)<0)
sprintf('The point (%f,%f) is a saddle point', ax(i),ay(i))
mkr='bv'; % marker
else
if (double(T2) < 0)
sprintf('The maximum value of the function is f(%f,%f)=%f', ax(i),ay(i),
T3)
legstr=[legstr,{'Maximum value of the function'}];% updating Legend
mkr='g+';% marker
else
sprintf('The minimum value of the function is f(%f,%f)=%f', ax(i),ay(i),
T3)
legstr=[legstr,{'Minimum value of the function'}];% updating Legend
mkr='r*'; % marker
end
end
hold on
plot3(ax(i),ay(i),T3,mkr,'Linewidth',4);
end
legend(legstr,'Location','Best');

% divergence

clear
clc;

syms x y
f=input("enter the funtion [f1,f2] :")
div(x,y)=divergence(f,[x,y])
P(x,y)=f(1);
Q(x,y)=f(2);
x=linspace(-4,4,20);
y=x;
[X,Y]=meshgrid(x,y);
U=P(X,Y);
V=Q(X,Y);
figure
pcolor(X,Y,div(X,Y))
hold on;
quiver(X,Y,U,V,1)
axis on
hold off;
title('vector field of F(x,y)=(f1,f2)');

% curl

clear
clc
syms x y z
f=input("enter the 3d vectir function in the form [f1,f2,f3]");
P(x,y,z)=f(1);
Q(x,y,z)=f(2);
R(x,y,z)=f(3);
crl=curl(f,[x,y,z])
C1(x,y,z)=crl(1);
C2(x,y,z)=crl(2);
C3(x,y,z)=crl(3);
x=linspace(-4,4,10);
y=x;
z=x;
[X,Y,Z]=meshgrid(x,y,z);
U=P(X,Y,Z);
V=Q(X,Y,Z);
W=R(X,Y,Z);
CR1=C1(X,Y,Z);
CR2=C2(X,Y,Z);
CR3=C3(X,Y,Z);
figure;
subplot(1,2,1);
quiver3(X,Y,Z,U,V,W);
title('3d view of vector field');
subplot(1,2,2);
quiver3(X,Y,Z,CR1,CR2,CR3);
title("3d view of curl");

# volume of solid of revolution
%Volume of the Solid of Revolution

clc
clear all
syms x
f = x^2+2;
fL = 0:10; %Enter the interval on which the function is defined
yr = 3; %the axis of rotation y = c
iL = 0:2; %the integration limits
Volume = pi*int((f-yr)^2,iL(1),iL(2));
disp(['Volume is: ', num2str(double(Volume))])
fx = inline(vectorize(f));
xvals = linspace(fL(1),fL(2),201);
xvalsr = fliplr(xvals);
xivals = linspace(iL(1),iL(2),201);
xivalsr = fliplr(xivals);
xlim = [fL(1) fL(2)+0.5];
ylim = fx(xlim);
figure('Position',[100 200 560 420])
subplot(2,1,1)
hold on;
plot(xvals,fx(xvals),'-b','LineWidth',2);
fill([xvals xvalsr],[fx(xvals) ones(size(xvalsr))*yr],[0.8 0.8
0.8],'FaceAlpha',0.8)
plot([fL(1) fL(2)],[yr yr],'-r','LineWidth',2);
legend('Function Plot','Filled Region','Axis of Rotation','Location','Best');
title('Function y=f(x) and Region');
set(gca,'XLim',xlim)
xlabel('x-axis');
ylabel('y-axis');
[X,Y,Z] = cylinder(fx(xivals)- yr,100);
figure('Position',[700 200 560 420])
Z = iL(1) + Z.*(iL(2)-iL(1));
surf(Z,Y+yr,X,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
hold on;
plot([iL(1) iL(2)],[yr yr],'-r','LineWidth',2);
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
view(22,11);

```