Mac11 Matlab Manual
Mac11 Matlab Manual
Engineering Stream
MAC11
MATLAB
Manual for
CSE, ISE, CS(CS), CS(AIML),
AI&ML, AI&DS, BT
Department of Mathematics
Ramaiah Institute of Technology,
Bengaluru - 560054
Matlab Manual for MAC11
Introduction to MATLAB
When you start MATLAB, the desktop appears in its default layout.
Plotting XY Data
Syntax
plot(X,Y, 'options')
creates a 2-D line plot of the data in Y versus the corresponding values in X, where X and Y are
vectors of the same length.
Plotting function
fplot(f,xinterval)
plots expression or function f over the specified interval. Specify the interval as a two-element vector
of the form [xmin xmax].
If we did not mention xinterval, fplot plots the function f over the default interval [-5 5] for x
Example
Plot the functions 𝑦1 = 50 cos 𝑥 sin 𝑥 , 𝑦2 = 4𝑥 3 − 4𝑥 + 14, 𝑦3 = 10𝑥 in the range [−2,2]
Using plot
clc
clear
close
x = [-2:0.01:2];
%Define the functions to plot
y1 = 50*cos(x).*sin(x);
y2 = 4*x.^3-4*x+14;
y3 = 10*x;
plot(x,y1,'b','linewidth',1)
hold on
plot(x,y2,'--r','linewidth',1)
plot(x,y3,'-.m','linewidth',1.5)
hold off
%Customization (Optional)
xlabel('\bf x-Axis'); ylabel('\bf y-Axis')
title('\fontname{Arial} Cartesian Plot','fontsize',14)
legend('y1','y2','y3')
Output
syms x
y1 = 50*cos(x)*sin(x);
y2 = 4*x^3-4*x+14;
y3 = 10*x
fplot([y1,y2,y3],[-2,2])
%Customization (Optional)
xlabel('\bf x-Axis'); ylabel('\bf y-Axis')
title('Cartesian Plot','fontsize',14)
legend('y1','y2','y3')
Syntax
polarplot(theta,rho)
plots a line in polar coordinates, with theta indicating the angle in radians and rho indicating the radius
value for each point. The inputs must be vectors of equal length or matrices of equal size.
Example
Plot the graph of the polar curves 𝑟 = cos 2𝜃 ; 𝑟 = sin 3𝜃
clc Output
clear
close all
t=linspace(0,2*pi);
polarplot(t,r1,'m',t,r2,'b','linewidth',2);
Exercise:
𝒂𝜽 𝟑
Hint: Input for : 2*t./(1+t), 𝒓𝟑 = 𝟖 𝐜𝐨𝐬 𝟑𝜽 ⇒ 𝒓 = √𝟖 𝐜𝐨𝐬 𝟑𝜽: nthroot(8*cos(3*t),3)
𝟏+𝜽
Algorithm:
𝑟′
• For a given curve 𝑟 = 𝑓(𝜃), find 𝜙 = cot −1 ( ), where 𝑟 ′ = 𝑑𝑟/𝑑𝜃
𝑟
clear
clc
close
syms theta
%Get the curve
r1=input("Enter the first curve r1(theta): r1=");
%Find phi1
phi1=simplify(acot(diff(r1)/r1));
%display phi1
fprintf("\n Angle between radius vector and tangent vector to the curve %s:\n phi=
%s",r1,phi1)
Output
Algorithm:
𝑟′
• For a given curve 𝑟1 = 𝑓1(𝜃), 𝑟2 = 𝑓2(𝜃), find 𝜙1 and 𝜙2 using 𝜙 = cot −1 ( ), where 𝑟 ′ = 𝑑𝑟/𝑑𝜃
𝑟
• Solve given curves for 𝜃 value
• Get the required appropriate 𝜃 value from the solution
• Find |𝜙2 − 𝜙1| by substituting obtained 𝜃 value
clear
clc
close
syms theta
phi1=simplify(acot(diff(r1)/r1));
phi2=simplify(acot(diff(r2)/r2));
Output
Enter the first curve r1(theta): r1=2*(1+cos(theta))
Enter the second curve r2(theta): r2=2*(1-cos(theta))
Angle between radius vector and tangent vector to the curve 2*cos(theta) + 2:
phi1= -acot(sin(theta)/(cos(theta) + 1))
Angle between radius vector and tangent vector to the curve 2 - 2*cos(theta):
phi2= -acot(sin(theta)/(cos(theta) - 1))
The values of theta at the point of intersection are: S =
pi/2
Choose the value of theta: pi/2
Angle between given polar curves = 1.570796 or 1.570796
Exercise:
𝒂
Hint: Input for 𝒓 = : 2/((log(theta)))
𝐥𝐨𝐠 𝜽
Syntax
diff(f,var,n)
computes the nth derivative of f with respect to var.
Example1
𝑥
𝜕𝑈
Find all the first order and second order partial derivatives of the function 𝑈 = 𝑒 𝑦 . Also, find at x=2,
𝜕𝑥
𝜕𝑈 𝜕𝑈
at y=2 and at x=2 & y=3.
𝜕𝑥 𝜕𝑦
clear
clc
syms x y
%Define U
U(x,y)=exp(x/y);
%First derivatives
Ux=diff(U,x);
Uy=diff(U,y);
%Second derivatives
Uxx=simplify(diff(Ux,x));
Uyy=simplify(diff(Uy,y));
Uxy=simplify(diff(Ux,y));
Uyx=simplify(diff(Uy,x));
U1=Ux(2,y);
U2=Ux(x,2);
U3=Uy(2,3);
Output
The first order partial derivatives are
Ux = exp(x/y)/y
Uy = -(x*exp(x/y))/y^2
Example 2
1 z z
If z = then prove that x −y = y2 z3 .
y − 2 xy + 1
2 x y
else
fprintf('\n The given condition is not satisfied')
end
Output
LHS =
y^2/(- 2*x*y + y^2 + 1)^(3/2)
RHS =
y^2/(- 2*x*y + y^2 + 1)^(3/2)
The given condition is satisfied
Jacobian
jacobian([u1,u2,…],[x1,x2,…])
computes the Jacobian of a vector function which is a matrix of the partial derivatives of that function
• To find the determinant find the determinant of the resultant Jacobian matrix.
Example 1
v = x+ y (u, v)
If u = x − 2 y and
2
then find the Jacobian . Also, find the value of Jacobian at (1, 0).
( x, y )
clear all
clc
syms x y u v
u(x,y)=input('Enter u(x,y):');
v(x,y)=input('Enter v(x,y):');
J(x,y)=simplify(det(jacobian([u,v],[x,y])));
fprintf('\n J((u,v)/(x,y))= %s \n', J);
Output
Enter u(x,y):x^2-2*y
Enter v(x,y):x+y
J((u,v)/(x,y))= 2*x + 2
Enter the point in the form [a,b] : [1,0]
J((u,v)/(x,y)) at (1,0) is 4
Example 2
(u, v)
If u = x2 − y2 and v = 2 xy where x = r cos t , y = r sin t then find the Jacobian . Also, show
( x, y )
(u, v ) (u, v )
that = 4r 3 and hence find the value of Jacobian at (3,1).
(r , t ) (r , t )
Output
Enter u(x,y):x^2-y^2
Enter v(x,y):2*x*y
Enter x(r,t):r*cos(t)
Enter y(r,t):r*sin(t)
J((u,v)/(r,t))=4*r^3
Example 3
(u, v, w)
If u = x sin y cos z , v = x sin y sin z and w = x cos y then find the Jacobian .
( x, y, z )
clear all
clc
syms x y z u v w
u(x,y,z)=input('Enter u(x,y,z):');
v(x,y,z)=input('Enter v(x,y,z):');
w(x,y,z)=input('Enter w(x,y,z):');
J(x,y,z)=simplify(det(jacobian([u,v,w],[x,y,z])));
fprintf('\n J((u,v,w)/(x,y,z))= %s \n', J);
Output
Enter u(x,y,z):x*sin(y)*cos(z)
Enter v(x,y,z):x*sin(y)*sin(z)
Enter w(x,y,z):x*cos(y)
J((u,v,w)/(x,y,z))= x^2*sin(y)
y z u u u
a) If u= + the show that x + y +z =0
z x x y z
1 1 log x − log y f f
b) If f = + + then prove that x + y + 2 f = 0.
x 2
xy x +y
2 2
x y
x3 + y3 u u 5
c) If u= then prove that x +y = u.
x+ y x y 2
(u, v, w)
d) If u = x + 3 y 2 − z 2 , v = 4 x 2 yz, w = 2 z 2 − xy then evaluate at (1,-1,0).
( x, y , z )
( x, y)
e) If x = e v sec u and y = e v tan u then find the Jacobian
(u, v)
(u, v )
f) If u = x 2 − 2y 2 and v = 2 x 2 − y 2 where x = r cos , y = r sin then show that = 6r 3 sin 2 .
(r , )
(u, v, w)
g) If u = yz v = zx , w = xy and x = r cos sin , y = r sin sin , z = r cos then find .
(r , , )
Syntax
returns the gradient vector of symbolic scalar field f with respect to
g = gradient(f,v) vector v in Cartesian coordinates.
Example 1
Find gradient of a given scalar function 𝑓 = 2𝑦𝑧𝑠𝑖𝑛(𝑥) + 3𝑥𝑠𝑖𝑛(𝑧)cos(𝑦) at (1,2,3)
clear
clc
syms x y z
f(x,y,z) =input("Enter the function f(x,y,z):");
gradf=(simplify(gradient(f,[x y z])));
fprintf("grad(f)=%s\n",gradf)
p=input('\n Enter the point in the form [a,b,c] : ');
val=vpa(gradf(p(1),p(2),p(3)));
fprintf('\n grad(f) at (%d,%d,%d) is (%.4f)i + (%.4f)j + (%.4f)k
\n',p(1),p(2),p(3),val(1),val(2),val(3))
Output
Enter the function f(x,y,z):2*y*z*sin(x) + 3*x*sin(z)*cos(y)
grad(f)=[3*cos(y)*sin(z) + 2*y*z*cos(x); 2*z*sin(x) - 3*x*sin(y)*sin(z); 2*y*sin(x) +
3*x*cos(y)*cos(z)]
Enter the point in the form [a,b,c] : [1,2,3]
grad(f) at (1,2,3) is (6.3074)i + (4.6639)j + (4.6018)k
Example 2
Find the divergence of the given vector field 𝑓 = 𝑥𝑦𝑖 + 2𝑥𝑦 2 + 3𝑥𝑧 3 𝑘 at (3,4,5).
clear all
clc
syms x y z
F =input('Enter the components of vector F in [x y z] form : ');
div(x,y,z)=divergence(F,[x y z]);
fprintf('\n div(F) = %s \n',div);
p=input('\n Enter the point in the form [a,b,c] : ');
val=div(p(1),p(2),p(3));
fprintf('\n div(F) at (%d,%d,%d) is %d \n',p(1),p(2),p(3),val);
Example 3
Find the gradient of the scalar function 𝑓 = −(sin(𝑥) + sin(𝑦))2 and interpret geometrically
clear all
clc
syms x y
f = input("Enter the function f(x,y):");
gradf = gradient(f,[x y])
[X1, Y1] = meshgrid(-1:.1:1,-1:.1:1);
G1 = subs(gradf(1),[x y],{X1,Y1});
G2 = subs(gradf(2),[x y],{X1,Y1});
quiver(X1,Y1,G1,G2)
Output
gradf =
-2*cos(x)*(sin(x) + sin(y))
-2*cos(y)*(sin(x) + sin(y))
Example 4
Find the gradient of the scalar function 𝑓 = 𝑥𝑦 2 + 𝑦𝑧 2 + 𝑧𝑥 2 and interpret geometrically.
clear all
clc
syms x y z
f = input("Enter the function f(x,y,z):");
gradf = gradient(f,[x y z])
[X1, Y1, Z1] = meshgrid(-1:.2:1,-1:.2:1,-1:.2:1);
G1 = subs(gradf(1),[x y z],{X1,Y1,Z1});
G2 = subs(gradf(2),[x y z],{X1,Y1,Z1});
G3 = subs(gradf(3),[x y z],{X1,Y1,Z1});
quiver3(X1,Y1,Z1,G1,G2,G3)
xlabel('X')
ylabel('Y')
zlabel('Z')
Output
gradf =
2*x*z + y^2
2*x*y + z^2
x^2 + 2*y*z
clear
clc
syms x y z
f(x,y,z) =input("Enter the scalar function f(x,y,z):");
L=(simplify(laplacian(f,[x y z])));
fprintf("Laplacian of f(x,y,z) is %s \n",L)
Output
Enter the scalar function f(x,y,z):x^3 + y^2 - log(z)
Laplacian of f(x,y,z) is 6*x + 1/z^2 + 2
Example 6
To find directional derivative of function 𝑥𝑦 2 + 𝑦𝑧 2 + 𝑧𝑥 2 in the direction of the vector 𝑖 + 𝑗 + 𝑘 at (1,2,3)
clear all
clc
syms x y z
f= input("Enter the function f(x,y,z):");
gradf = gradient(f, [x y z])
n=input('\nEnter the components of directional vector as [x y z]:');
m = n/norm(n);
D(x,y,z) = simplify(dot(gradf',m));
fprintf('\nDirectional derivative is %s\n', D)
p=input('\nEnter the point as [a,b,c]:');
val=vpa(D(p(1),p(2),p(3)));
fprintf('Directional derivative at (%d,%d,%d) is %f\n', p(1),p(2),p(3),val)
Output
Enter the function f(x,y,z):x^2*z + x*y^2 + y*z^2
gradf =
2*x*z + y^2
2*x*y + z^2
x^2 + 2*y*z
Enter the components of directional vector as [x y z]:[1 1 1]
Directional derivative is (3^(1/2)*(x + y + z)^2)/3
Enter the point as [a,b,c]:[1,2,3]
Directional derivative at (1,2,3) is 20.784610
Exercise:
1. Find gradient of a given scalar function 𝒇 = 𝒙𝒚𝒛 + 𝟑𝒚𝒔𝒊𝒏(𝒛)𝐜𝐨𝐬(𝒚) at the point (1,2,3).
3. Find div𝑭 ̂.
⃗ at the point (2,3,4) where ⃗𝑭 = (𝒚𝟐 + 𝒛𝟐 − 𝒙𝟐 )𝒊̂ + (𝒛𝟐 + 𝒙𝟐 − 𝒚𝟐 )𝒋̂ + (𝒙𝟐 + 𝒚𝟐 − 𝒛𝟐 )𝒌
6. To find directional derivative of function 𝒙𝒄𝒐𝒔𝒚 + 𝒙𝒚𝒛𝟐 + 𝒚𝒛𝒄𝒐𝒔𝒙in the direction of the vector 𝒙𝒚𝒊̂ +
̂.
𝒙𝒚𝒛𝒋̂ + 𝒚𝒛𝒌
7. Find the directional derivative of = 𝒙𝟐 − 𝟐𝒙𝒚 + 𝒛𝟑 at the point (1,−2,−1) along the vector 𝟐𝒊̂ − 𝟒𝒋̂ + 𝟒𝒌
̂.
clear
clc
% Region of integration
xL=input("Enter lower limit of x")
xU=input("Enter Upper limit of x")
x = linspace(xL, xU); % x limits
yL=input("Enter lower limit of y")
yU=input("Enter Upper limit of y")
Li = yU >= yL ; % Logical Vector
figure
plot(x,yU,x,yL)
hold on
patch([x(Li) fliplr(x(Li))], [yU(Li) fliplr(yL(Li))], 'b')
hold off
grid
Example:
With the program to mark the region of integration in the following double integrals:
2 2x 4 x
1) 0 x2
f ( x, y ) dy dx f ( x, y) dy dx
2) 1 2
Output Output
Enter lower limit of x: 0 Enter lower limit of x: 1
Enter Upper limit of x: 2 Enter Upper limit of x: 4
Enter lower limit of y: x.^2 Enter lower limit of y: 2+0.*x
Enter Upper limit of y: 2.*x Enter Upper limit of y: sqrt(x)
ii) For the polar plot patch won't work (instead of that we need to use polyfill but it is not
user-friendly).
Exercise:
2 4− x 2 sin x 42 x 2 3− y
a)
0 2− x
f ( x, y ) dy dx b)
0 0
f ( x, y ) dy dx c)
0 x 2
f ( x, y ) dy dx d) f ( x, y) dy dx
0 y
4 4
clear
clc
syms x y
f = matlabFunction(input("Enter the integrand: "));
disp('f(x,y) :');
disp(f);
d = integral2(f,xL,xU,yL,yU);
disp("Double Integral of f(x,y) :");
disp(d);
2 3
a) ∫1 ∫2 (𝑥 − 1/𝑦)2 𝑑𝑥𝑑𝑦 b)
1
∫0 ∫𝑥 𝑥𝑦 𝑑𝑦𝑑𝑥
√𝑥
Output: Output:
Enter the integrand: (x-1/y)^2 Enter the integrand: x*y
f(x,y) : f(x,y) :
@(x,y) (x-1./y).^2 @(x,y)x.*y
Enter lower limit of x: 1 Enter lower limit of x: 0
Enter Upper limit of x: 2 Enter Upper limit of x: 1
Enter lower limit of y: 2 Enter lower limit of y: @(x) x
Enter Upper limit of y: 3 Enter Upper limit of y: @(x) sqrt(x)
Double Integral of f(x,y) : 1.2836 Double Integral of f(x,y) :
0.0417
Exercise:
a
a a− x2 3 x2 +a2
x
a − x − y dy dx
2 2 2
a) (ans:0.5236) b) dy dx (ans:0.1215)
0 0 0 0 x + y2 + a2
2
𝟐𝝅 𝝅 𝟐𝝅 𝒙
c) ∫𝝅 ∫𝟎 𝒚 𝒔𝒊𝒏𝒙 + 𝒙 𝒄𝒐𝒔𝒚 𝒅𝒙𝒅𝒚 (ans:9.8696) d) ∫𝝅 ∫𝟎 𝒚 𝒔𝒊𝒏𝒙 + 𝒙 𝒄𝒐𝒔𝒚 𝒅𝒙𝒅𝒚 (ans:32.0988)
NOTE: matlabFunction which converts the variable expression into to function handler, if the
integrand is a constant function then don’t use this converter. Just use
Triple Integral
clear
clc
syms x y z
f = matlabFunction(input("Enter the integrand f(x,y,z) : "));
disp('f(x,y,z) :');
disp(f);
d = integral3(f,xL,xU,yL,yU,zL,zU);
disp("Triple Integral of f(x,y,z) :");
disp(d);
(xyz )dx dy dz
1 2 2
e
2 x+ y+ z
a) b) dz dy dx
0 0 1 0 0 0
OUTPUT: OUTPUT:
Enter the integrand f(x,y,z): x*y*z^2 Enter the integrand f(x,y,z): exp(x+y+z)
f(x,y,z) : f(x,y,z) :
@(x,y,z)x.*y.*z.^2 @(x,y,z)exp(x+y+z)
Enter lower limit of x: 0 Enter lower limit of x: 0
Enter Upper limit of x: 1 Enter Upper limit of x: 1
Enter lower limit of y: 0 Enter lower limit of y: 0
Enter Upper limit of y: 2 Enter Upper limit of y: @(x) x
Enter lower limit of z: 1 Enter lower limit of z: 0
Enter Upper limit of z: 2 Enter Upper limit of z: @(x,y) x+y
Triple Integral of f(x,y,z) : 2.3333 Triple Integral of f(x,y,z) : 3.6263
Exercise:
1 1 y e log y e x 1 1− x 2 1− x 2 − y 2
a) xyz dz dx dy
0 0 0
b) log z dz dx dy
1 1 1
c)
0 0
0
xyz dx dy dz
NOTE: Use @(x,y) if the limit is a function of two variable, @(x) for function of one variable
switch option
case 1
y=input("Enter the function f(x): \n")
r=[x y];
F=input("Enter the vector function F(x,y)=[F1 F2]: F(x,y)")
dr=diff(r,x);
integrand1=dot(F,dr);
xL=input("Enter the lower limit of x:");
xU=input("Enter the Upper limit of x:");
line=int(integrand1,x,xL,xU)
case 2
x=input("Enter the function g(y): \n")
r=[x y];
F=input("Enter the vector function F(x,y)=[F1 F2]: F(x,y)")
dr=diff(r,y);
integrand1=dot(F,dr);
yL=input("Enter the lower limit of y:");
yU=input("Enter the Upper limit of y:");
line=int(integrand1,y,yL,yU)
otherwise
fprintf("Give the proper input")
end
end
%%%%%%%%%%%%%%%% Line Integral definition ends %%%%%%%%%%%%%%%%%%
clear
clc
syms x y z t
x=input("Enter x(t):"); % If x ,y, z is a function of ‘t’
y=input("Enter y(t):");
z=input("Enter z(t):");
r=[x y z];
F=input("Enter the vector function F(x,y,z):")
dr=diff(r,t);
integrand1=dot(F,dr);
tl=input("Enter the lower limit of t:");
tu=input("Enter the Upper limit of t:");
line=int(integrand1,t,tl,tu)
Example 1
Evaluate ∫𝑐 𝐹 ⋅ 𝑑𝑟, where 𝑐 is the curve given by 𝑥 = 2𝑡 2 , 𝑦 = 𝑡, 𝑧 = 𝑡 3 from (0,0,0) to (2,1,1) and 𝐹 =
(2𝑦 + 3)𝑖̂ + 𝑥𝑧𝑗̂ + (𝑦𝑧 − 𝑥)𝑘̂.
Output
Enter x(t):2*t^2
Enter y(t):t
Enter z(t):t^3
Enter the vector function F(x,y,z):[2*y+3 x*z yz-x]
Enter the vector function F(x,y,z):[2*y+3 x*z y*z-x]
F =
[3 + 2*t, 2*t^5, - 2*t^2 + t^4]
Enter the Lower limit of t:0
Enter the Upper limit of t:1
line =
288/35
Exercise:
1. If F = xy iˆ + yz ˆj + zx kˆ evaluate F . dr where c is the curve represented by
c
x = t, y = t , z = t , − 1 t 1 .
2 3
2. Find the circulation of F round the curve c , where F = (x − y ) iˆ + (x + y ) ˆj and c is the circle
x2 + y2 = 4 , z = 0 .
3. Find the total work done by a force F = 2 xy iˆ − 4 z ˆj + 5 x kˆ along the curve
x = t , y = 2t + 1, z = t
2 3
from t= 0 to t = 1 .
4. Evaluate F . dr , where F = cos y iˆ − x sin y ˆj and c is the curve y = 1 − x 2 in xy -plane from
c
(1, 0) to (0, 1).
Greens theorem
𝑀(𝑥, 𝑦), 𝑁(𝑥, 𝑦) be continuous in a region 𝑅 of 𝑥𝑦 plane bounded by a closed curve 𝑐 then
𝜕𝑁 𝜕𝑀
∮ 𝑀𝑑𝑥 + 𝑁𝑑𝑦 = ∫ ∫ − 𝑑𝑥𝑑𝑦
𝑐 𝑅 𝜕𝑥 𝜕𝑦
Algorithm
• Create a function for LHS: Evaluate ∮𝑐 𝑀𝑑𝑥 + 𝑁𝑑𝑦 along the curve 𝑐 using Line integral
𝜕𝑁 𝜕𝑀
• Create a function for RHS: Evaluate ∫ ∫𝑅 − 𝑑𝑥𝑑𝑦 using multiple integrals
𝜕𝑥 𝜕𝑦
• Check whether LHS=RHS or not
syms x y
LHS=0;
%Get the number of sub path in the curve C
n=input("How many sub curves are ther in the curve C? :")
%Calculate the line integral along each path (LHS)
for i=1:n
line(i)=LineIntegral(x,y);
LHS=vpa(LHS+line(i))
end
%Calculate the double integral (RHS)
RHS=vpa(MultiIntegral(x,y))
switch option
case 1
y=input("Enter the function f(x): \n")
r=[x y];
F=input("Enter the vector function F(x,y)=[F1 F2]: F(x,y)=")
dr=diff(r,x);
integrand1=dot(F,dr);
xL=input("Enter the lower limit of x:");
xU=input("Enter the Upper limit of x:");
line=int(integrand1,x,xL,xU)
case 2
x=input("Enter the function g(y): \n")
r=[x y];
F=input("Enter the vector function F(x,y)=[F1 F2]: F(x,y)=")
dr=diff(r,y);
integrand1=dot(F,dr);
yL=input("Enter the lower limit of y:");
yU=input("Enter the Upper limit of y:");
line=int(integrand1,y,yL,yU)
otherwise
fprintf("Give the proper input")
end
disp('f(x,y) :');
disp(f);
d = int(int(f,y,yL,yU),x,xL,xU);
end
%%%%%%%%%%%%%%%% Double Integral definition ends %%%%%%%%%%%%%%%%%%
Example 1
2x
y = 0, x = , y= .
2
Output
How many subcurves are ther in the curve C? :3
n =
3
1: y=f(x)
2: x=g(y)
1
option =
1
Enter the function f(x):
0
y =
0
Enter the vector function F(x,y)=[F1 F2]: F(x,y)=[y-sin(x) cos(y)]
F =
[-sin(x), 1]
Enter the lower limit of x:0
Enter the Upper limit of x:pi/2
line =
-1
LHS =
-1.0
1: y=f(x)
2: x=g(y)
2
option =
LHS =
-0.1585290151921034933474976783697
1: y=f(x)
2: x=g(y)
1
option =
1
Enter the function f(x):
2*x/pi
y =
(2*x)/pi
Enter the vector function F(x,y)=[F1 F2]: F(x,y)=[y-sin(x) cos(y)]
F =
[(2*x)/pi - sin(x), cos((2*x)/pi)]
Enter the lower limit of x:pi/2
Enter the Upper limit of x:0
line =
1 - sin(1) - pi/4
LHS =
-0.78539816339744830961566084581988
RHS =
-0.78539816339744830961566084581988
Exercise:
1. Verify Green’s theorem for ∫𝒄(𝟑𝒙𝟐 − 𝟖𝒚𝟐 )𝒅𝒙 + (𝟒𝒚 − 𝟔𝒙𝒚)𝒅𝒚 where c is the plane triangle enclosed by the
line 𝒙 = 𝟎, 𝒚 = 𝟎, 𝒙 + 𝒚 = 𝟏.
2. . Verify Green’s theorem for ∫𝒄(𝒙𝟐 − 𝒚𝟐 )𝒅𝒙 + 𝟐𝒙𝒚𝒅𝒚 where c is the rectangle bounded by rectangle 𝒚 =
𝟎, 𝒙 = 𝟎, 𝒚 = 𝒃 and 𝒙 = 𝒂.
Output
50*x + 20*y == 300
300 is multiple of gcd(50,20)=10, hence it has solution
Solution is : x=-30, y=90
General Solution [x,y]:
x=2*t - 30
y=90 - 5*t
Exercise:
2. Find all the solutions (x, y) to the Diophantine equation 11x + 13y = 369 for which x and y are both
positive.
clc
clear;
prompt1 = "Enter the first number: ";
m = input(prompt1); %Get the first number
prompt2 = "Enter the second number: ";
n = input(prompt2); %Get the first number
ans=euclid(m,n); %Call the recursive function euclid
if ans==-1
fprintf('Enter the numeric values\n')
elseif ans==-2
fprintf('Enter the integral values\n')
elseif ans==-3
fprintf('Enter the positive values\n')
else
fprintf('%d\n',ans)
end
end
Exercise
[g,u0,v0] = EuclidMatrix(m,a);
if ( mod(c,g) ) ~= 0
disp('No solutions.')
solutions = [];
return
end
u = u0 - (a / g);
v = v0 + (m / g);
x = v * (c / g);
y = u * (c / g);
S = @(k) x + k * (m/g);
solutions = mod(S(0:g-1),m);
fprintf('solution=%f\n',solutions)
Exercise: