0% found this document useful (0 votes)
46 views33 pages

Screenshot 2023-12-09 at 11.05.11 AM

The document contains descriptions of 25 MATLAB experiments involving plotting functions, solving equations, computing derivatives, integrals, and vector/multivariable calculus operations. Each experiment demonstrates a different mathematical concept and MATLAB functionality like plotting curves, solving equations symbolically, computing gradients/divergences/curls, and visualizing surfaces and vector fields. User input is requested in some experiments to allow custom functions and parameters.

Uploaded by

hey.imcorden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views33 pages

Screenshot 2023-12-09 at 11.05.11 AM

The document contains descriptions of 25 MATLAB experiments involving plotting functions, solving equations, computing derivatives, integrals, and vector/multivariable calculus operations. Each experiment demonstrates a different mathematical concept and MATLAB functionality like plotting curves, solving equations symbolically, computing gradients/divergences/curls, and visualizing surfaces and vector fields. User input is requested in some experiments to allow custom functions and parameters.

Uploaded by

hey.imcorden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Experiment-1

clc
clear all
close all

x=linspace(0,1);

plot(x,x.^2,'r')
hold on

plot(x,sin(x),'g.')
plot(x,exp(x),'m+')
legend('x^2','sin(x)','exp(x)')
Experiment-2

clc
clear all
close all

x=0:0.01:2*pi;

subplot(2,2,1)
plot(x, sin(x));

subplot(2,2,2)
plot(x, cos(x), 'r-*');

subplot(2,2,3)
plot(x, exp(-x), 'go');

subplot(2,2,4)
plot(x, sin(x), 'ms');
Experiment-3

clc
clear all
close all

syms x

f=sin(2*x)+cos(3*x);

figure(1);
ezplot(f);

figure(2);
ezplot(f, [0,3]);
Experiment-4

clc
clear all
close all

syms x

y=input("Enter the Function f in terms of x : ");

x1=input("Enter x value at which tangent : ");

D=[x1-2, x1+2];

ezplot(y, D);
hold on

yd = diff(y, x);
slope = subs(yd, x, x1);

y1=subs(y,x,x1);

plot(x1, y1, 'ko');

Tangent=slope*(x-x1)+y1;

Line=ezplot(Tangent, D);

set(Line, "color", "r");


Experiment-5

clc
clear all
close all

y=linspace(-10,10,1000);
plot(y,cos(y),'b',y,cos(2*y),'g.');

xlabel('x axis');
ylabel('y axis');
legend('cos(x).cos(2x)','location','northeast')
Experiment-6

clc
clear all
close all

t=linspace(0,2*pi,500);

x=cos(t);
y=sin(t);
z=sin(5*t);

comet3(x,y,z)
plot3(x,y,z,'g*','markersize',7)

xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
title('3D Curve')
Experiment-7

clc
clear all
close all

syms x y;

f=2*(x^2+y^2);

ezsurf(f);

colormap winter;
Experiment-8

clc
clear all
close all

x=-1:0.5:1;

y=-1:0.5:1;

[x,y] = meshgrid(x,y);

z = x.*y.^2-x.^3;

surf(x,y,z);

colormap spring;

shading interp;
Experiment-9

clc
clear all
close all

syms x real

f=input("Enter the Function f(x) : ");

fx=diff(f,x);

fxx=diff(fx,x);

ezplot(f);

hold on

D=[0,5];

L1=ezplot(f, D);
set(L1, "color", "b");

hold on

L2=ezplot(fx, D);
set(L2, "color", "r");

L3=ezplot(fxx, D);
set(L3, "color", "g");

legend("f", "fx", "fxx");


legend("location", "northeastoutside");
Experiment-10

clc
clear all
close all

syms x real;

f=input("Enter the Function f(x) : ");

fx=diff(f);
fxx=diff(fx);

c=solve(fx);
c=double(c);

for i=1:length(c)
T1=subs(fxx, x, c(i));
T1=double(T1);

T3=subs(f, x, c(i));

if (T1==0)

print("The point maybe a point of inflection");

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
Experiment-11

clc
clear all
close all

syms x y real;

y1=input("Enter the First (f) curve : ");


y2=input("Enter the Second (g) curve : ");

t=solve(y1-y2);

B=double(t);
n=length(B);

m1=min(B);
m2=max(B);

ex1=ezplot(y1, [m1-1, m2+1]);

hold on;

Ta=0;

ex2=ezplot(y2, [m1-1, m2+1]);

for i=1:n-1

A=int(y1-y2, t(i), t(i+1));


Ta = Ta + abs(A);
x1 = linspace(B(i), B(i+1));
yy1=subs(y1, x, x1);
yy2=subs(y2, x, x1);

xx=[x1, fliplr(x1)];
yy=[yy1, fliplr(yy2)];

fill(xx, yy, "g");

end
hold on
Experiment-12

clc
clear all
close all

syms x;

f=input("Enter the Function : ");


fL=input("Enter the interval on which the function is defined : ");

yr=input("Enter the axis of rotation y=c (enter only c value) : ");


iL=input("Enter the Integration Limits : ");

Volume=pi*int((f-yr)^2, iL(1), iL(2));

disp(['Volume is : ', num2str(double(Volume))]);

fx=inline(vectorize(f));
xivals=linspace(iL(1),iL(2),201);

[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);
Experiment-13

clc
clear all
close all
clearvars

syms x y L;

f=input("Enter the Function f(x, y): ");


g=input("Enter the constraint function g(x, y): ");

F=f+L*g;

gradF=jacobian(F, [x, y]);

[L, x1, y1] = solve(g, gradF(1), gradF(2), "Real", true);

x1=double(x1);
y1=double(y1);

xmx=max(x1); xmn=min(x1);

ymx=max(y1); ymn=min(y1);

range=[xmn-3 xmx+3 ymn-3 ymx+3];

ezmesh(f, range); hold on; grid on;

h=ezplot(g, range); set(h, "LineWidth", 2);

tmp=get(h, "contourMatrix");
xdt=tmp(1, 2:end);
ydt=tmp(2, 2:end);
zdt=double(subs(f, {x, y}, {xdt, ydt}));

plot3(xdt, ydt, zdt, "-r", "LineWidth", 2); axis(range)

for i=1:numel(x1)

G(i)=subs(f, [x, y], [x1(i), y1(i)]);


plot3(x1(i), y1(i), G(i), "*k", "MarkerSize", 20);

end

title("Constrained Maxima/Minima")
display(double(G));
Experiment-14

clc
clear all
close all
clearvars;

syms x y z L;

f=input("Enter the Function f(x, y, z): ");


g=input("Enter the Constraint function g(x, y, z): ");

F=f+L*g;

gradF=jacobian(F, [x, y, z]);


[L, x1, y1, z1]=solve(g, gradF(1), gradF(2), gradF(3));

Z=double([x1 y1 z1]);

Dup=subs(f, x, Z(1,1));
Dup=subs(Dup, y, Z(1,2));
Dup=subs(Dup, z, Z(1,3));

fprintf("The Maximum value of the function is %d\n", double(Dup));

Dup=subs(f, x, Z(2,1));
Dup=subs(Dup, y, Z(2,2));
Dup=subs(Dup, z, Z(2,3));

fprintf("The Minimum value of the function is %d\n", double(Dup));


Experiment-15

clc
clear all
close all
clearvars

syms x y L;

f=(x^2)*(y^2);
g=2*x+4*y-40;

F=f+L*g;

gradF=jacobian(F, [x, y]);

[L, x1, y1] = solve(g, gradF(1), gradF(2), "Real", true);

Z=double([x1 y1]);

Max=1e10;
[rows, cols]=size(Z);

for i=1:rows

Dup=subs(f, x, Z(i,1));
Dup=subs(Dup, y, Z(i,2));
Dup=double(Dup);

if Dup>Max

Max=Dup;

end

end

fprintf("The Maximum value of the function is %d\n", double(Dup));


Experiment-16

clc
clear all
close all

syms x y z

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)


Experiment-17
clc
clear all
close all

syms x y z

int(int(3-x-y, x, y, 1), y, 0 ,1)

viewSolidone(z, 0+0*x+0*y, 3-x-y, x, y, 1, y, 0, 1)


Experiment-18

clc
clear all
close all

syms x y z

int(int((4*x+2), y, x^2, 2*x), x, 0, 2)

viewSolid(z, 0+0*x+0*y, 4*x+2, y, x^2, 2*x, x, 0, 2)


Experiment-19

%Find the Volume of the Region Enclosed by the surfaces z=x^2+3y^2 and
%z=8-x^2-y^2

clc
clear all
close all

syms x y z;

xa=-2;
xb=2;

ya=-sqrt(2-x^2/2);
yb=sqrt(2-x^2/2);

za=x^2+3*y^2;
zb=8-x^2-y^2;

I=double(int(int(int(1+0*z, z, za, zb), y, ya, yb), x, xa, xb))


viewSolid(z, za, zb, y, ya, yb, x, xa, xb)
Experiment-20

%Find the Volume of the Region Enclosed by the surfaces z=0 and x+z=3. The
%Limits of Integration are z=0 to 3, x=-sqrt(4-y) to sqrt(4-y) and y=-2 to
%2

clc
clear all
close all

syms x y z;

xa=-sqrt(4-y^2);
xb=sqrt(4-y^2);

ya=-2;
yb=2;

za=0+0*x+0*y;
zb=3-x-0*y;

I=double(int(int(int(1+0*z, z, za, zb), x, xa, xb), y, ya, yb))


viewSolidone(z, za, zb, x, xa, xb, y, ya, yb)
Experiment-21

%Find the Volume of the Region Enclosed by the surfaces z=0 and x+z=3. The
%Limits of Integration are z=0 to 3, x=-sqrt(4-y) to sqrt(4-y) and y=-2 to
%2

clc
clear all
close all

syms x y z real;

xa=0;
xb=1;

ya=0+0*x;
yb=1-x;

za=0*x+0*y;
zb=cos(pi*x/2)+0*y;

I=double(int(int(int(1+0*z, z, za, zb), y, ya, yb), x, xa, xb))


viewSolid(z, za, zb, y, ya, yb, x, xa, xb)
Experiment-22

clc
clear all
close all

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]);
Experiment-23

clc
clear all
close all

syms x y

f=input("Enter the 2D Vector Function in the form [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));
shading interp;

hold on;

quiver(X, Y, U, V, 1);

axis on;
hold off;

title("Vector Field of F(x, y)=[f1, f2]");


Experiment-24

clc
clear all
close all

syms x y z

f=input("Enter the 3D Vector 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("3-D view of Vector Field");

subplot(1, 2, 2);
quiver3(X, Y, Z, CR1, CR2, CR3);
title("3-D view of a Curl")
Experiment-25

clc
clear all
close all

syms x y t

f=input("Enter the components of 2D vector function [u,v] : ");


r=input("Enter x, y in parametric form : ");
I=input("Enter the limits of Integration for t in the form [a, b] : ");

a=I(1); b=I(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");
Experiment-26

clc
clear all
close all

syms x y z t

f=input("Enter the components of 3D vector function [u,v,w] : ");


r=input("Enter x, y, z in parametric form : ");
I=input("Enter the limits of Integration for t in the form [a, b] : ");

a=I(1); b=I(2);

dr=diff(r, t);
F=subs(f, {x, y, z}, r);
Fdr=sum(F.*dr);

I=int(Fdr, t, a, b);

P(x, y, z)=f(1); Q(x, y, z)=f(2); R(x, y, z)=f(3);

x1=linspace(0, 1, 10); y1=x1; z1=x1;

[X, Y, Z]=meshgrid(x1, y1, z1);


U=P(X, Y, Z); V=Q(X, Y, Z); W=R(X, Y, Z);

quiver3(X, Y, Z, U, V, W, 1.5);
hold on

t1=linspace(0, 1, 10);
x=subs(r(1), t1); y=subs(r(2), t1); z=subs(r(3), t1);

plot3(x, y, z, "r");
Experiment-27

clc
clear all
close all

syms x y r t;

F=input("Enter the F vector as i and j order in vector form : ");

integrand=diff(F(2), x) - diff(F(1), y);

polarint=r*subs(integrand, [x, y], [r*cos(t), r*sin(t)]);

sol=int(int(polarint, r, 0, 3), t, 0, 2*pi);

P=inline(vectorize(F(1)), "x", "y");


Q=inline(vectorize(F(2)), "x", "y");

x=linspace(-3.2, 3.2, 10); y=x;

[X, Y]=meshgrid(x, y);

U=P(X, Y);
V=Q(X, Y);

quiver(X, Y, U, V);
hold on

fplot(3*cos(t), 3*sin(t), [0, 2*pi]);


axis equal;
Experiment-28

clc
clear all
close all

syms x y r t;

F=input("Enter the F vector as i and j order in vector form : ");

integrand=diff(F(2), x) - diff(F(1), y);

polarint=r*subs(integrand, [x, y], [r*cos(t), r*sin(t)]);

sol=int(int(polarint, r, 1, 2), t, 0, pi);

P=inline(vectorize(F(1)), "x", "y");


Q=inline(vectorize(F(2)), "x", "y");

x=linspace(-3.2, 3.2, 10); y=x;

[X, Y]=meshgrid(x, y);

U=P(X, Y);
V=Q(X, Y);

quiver(X, Y, U, V);
hold on

fplot(1*cos(t), 1*sin(t), [0, pi]);


fplot(2*cos(t), 2*sin(t), [0, pi]);
axis equal;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy