0% found this document useful (0 votes)
39 views10 pages

Matlab Assignment 3

nco ano paoubqjep

Uploaded by

gineethrs696
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)
39 views10 pages

Matlab Assignment 3

nco ano paoubqjep

Uploaded by

gineethrs696
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/ 10

Calculus Assignment – 3

Name: - Gineeth.R

Registration Number: - 24BAI1017


%To evaluate the definite integrals , Riemann sums and compares it.

MATLAB CODE :

clc

clear all

syms x

f = input('Enter the function f(x):');

a = input('Enter the lower limit of x:');

b = input('Enter the upper limit of x:');

n = input('Number of intervals:');

value = 0;

dx = (b-a)/n;

for k=1:n

c = a+k*dx;

d = subs(f,x,c);

value = value + d;

end

value = dx*value

figure(1)
ezplot(f,[a,b])

z = int(f,a,b)

figure(2)

rsums(f,a,b)

Q1) F(x) = (x^3 cos(x/2)+1/2)( √(4-x^2)) from x=-2 to x=2?

Ans)

In the Command Window:

Enter the function f(x):

(x^3*cos(x/2)+1/2).*(sqrt(4-x^2))

Enter the lower limit of x:

-2

Enter the upper limit of x:

Number of intervals:

10

value =

(2*96^(1/2)*((8*cos(1/5))/125 + 1/2))/25 - (2*96^(1/2)*((8*cos(1/5))/125 -


1/2))/25 - (2*84^(1/2)*((64*cos(2/5))/125 - 1/2))/25 +
(2*84^(1/2)*((64*cos(2/5))/125 + 1/2))/25 + 38/25

z=

int((4 - x^2)^(1/2)*(x^3*cos(x/2) + 1/2), x, -2, 2)

In the Figure Window :


%To find the area of the regions enclosed by curves and visualize it. (Note:The
following code will work if the input functions are polynomials (not
trigonometric)).

MATLAB CODE :

clc

clear all

syms x y real

y1 = input('Enter the first curve:');

y2 = input('Enter the second curve:');

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

TA = 0

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

if n>2
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

end

else

A = int(y1-y2,t(1),t(2))

TA = abs(A)

x1 = linspace(k(1),k(2));

yy1 = subs(y1,x,x1);

yy2 = subs(y2,x,x1);

x1 = [x1,fliplr(x1)];

yy = [yy1,fliplr(yy2)];

fill(x1,yy,'g')

end
Q2) Find the area of the regions enclosed by the curves y = -x^2+4x , y =
x^2-6x+5.

Ans)

In the Command Window :

Enter the first curve:

-x^2+4*x

Enter the second curve:

x^2-6*x+5

k=

0.5635

4.4365

n=

m1 =

0.5635

m2 =

4.4365

TA =

A=

5*15^(1/2)
TA =

5*15^(1/2)

In the Figure Window :-

Q3) Find the area of the regions enclosed by the curves y = 2x^5+3x^4-
5x^3+2x^2-x=1 , y = x^3-2x^2-5x+6.

Ans)

In the Command Window :

Enter the first curve:

2*x^5+3*x^4-5*x^3+2*x^2-x+1

Enter the second curve:

x^3-2*x^2-5*x+6

k=

0.8443

-0.9099
-2.7258

n=

m1 =

-2.7258

m2 =

0.8443

TA =

A=

2*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^2 - (4*root(z^5 +


(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1)^3)/3 - 2*root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 1)^2 + (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z,
1)^4)/2 + (4*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^3)/3 -
(3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1)^5)/5 - (3*root(z^5 +
(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^4)/2 - root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 1)^6/3 + (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2,
z, 2)^5)/5 + root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^6/3 +
5*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1) - 5*root(z^5 + (3*z^4)/2 -
3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)

TA =

2*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^2 - (4*root(z^5 +


(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1)^3)/3 - 2*root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 1)^2 + (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z,
1)^4)/2 + (4*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^3)/3 -
(3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1)^5)/5 - (3*root(z^5 +
(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^4)/2 - root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 1)^6/3 + (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2,
z, 2)^5)/5 + root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^6/3 +
5*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1) - 5*root(z^5 + (3*z^4)/2 -
3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)

A=

(3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^4)/2 - (4*root(z^5 +


(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^3)/3 - 2*root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 2)^2 - (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z,
2)^5)/5 + 2*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 5)^2 - root(z^5 +
(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^6/3 + (4*root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 5)^3)/3 - (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2,
z, 5)^4)/2 + (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 5)^5)/5 +
root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 5)^6/3 + 5*root(z^5 +
(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2) - 5*root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 5)

TA =

4*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^2 - (4*root(z^5 +


(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1)^3)/3 - 2*root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 1)^2 + (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z,
1)^4)/2 + (8*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^3)/3 -
(3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1)^5)/5 - 3*root(z^5 +
(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^4 - root(z^5 + (3*z^4)/2 - 3*z^3 +
2*z^2 + 2*z - 5/2, z, 1)^6/3 + (6*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2,
z, 2)^5)/5 - 2*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 5)^2 +
(2*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2)^6)/3 - (4*root(z^5 +
(3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 5)^3)/3 + (3*root(z^5 + (3*z^4)/2 - 3*z^3
+ 2*z^2 + 2*z - 5/2, z, 5)^4)/2 - (3*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z -
5/2, z, 5)^5)/5 - root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 5)^6/3 +
5*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z - 5/2, z, 1) - 10*root(z^5 + (3*z^4)/2
- 3*z^3 + 2*z^2 + 2*z - 5/2, z, 2) + 5*root(z^5 + (3*z^4)/2 - 3*z^3 + 2*z^2 + 2*z -
5/2, z, 5)

In the Figure Window :

--- THE END ---

You might also like