0% found this document useful (0 votes)
93 views23 pages

Nme File: Experiment 1 (A) CLC Clear All Close All

The document contains details of 8 experiments conducted on numerical methods. Experiment 1 generates a sine wave and 3D surface plot. Experiment 2 performs basic arithmetic operations on matrices input by the user. Experiment 3 calculates marks of students in different subjects and their grades. Experiment 4 solves algebraic, transcendental and simultaneous equations using symbolic computation. Experiment 5 calculates factorials and exponential, Taylor and Maclaurin series. Experiment 6 performs bisection method for root finding. Experiment 7 applies Newton-Raphson method to solve nonlinear equations. Experiment 8 solves linear systems using Gaussian elimination. Experiment 9 implements Simpson's 1/3 rule for numerical integration.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views23 pages

Nme File: Experiment 1 (A) CLC Clear All Close All

The document contains details of 8 experiments conducted on numerical methods. Experiment 1 generates a sine wave and 3D surface plot. Experiment 2 performs basic arithmetic operations on matrices input by the user. Experiment 3 calculates marks of students in different subjects and their grades. Experiment 4 solves algebraic, transcendental and simultaneous equations using symbolic computation. Experiment 5 calculates factorials and exponential, Taylor and Maclaurin series. Experiment 6 performs bisection method for root finding. Experiment 7 applies Newton-Raphson method to solve nonlinear equations. Experiment 8 solves linear systems using Gaussian elimination. Experiment 9 implements Simpson's 1/3 rule for numerical integration.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

NME FILE

EXPERIMENT 1

(A)

clc;

clear all;

close all;
j=1

for i=0:pi/1000:pi*2

x(j,:)=sin(i);

j=j+1;

end

figure;

plot(x)

title('Sine wave')

xlabel('Angle')

ylabel('Sine')

(B)

clc;

clear all;

close all;

j=1
for x=0:10

for y=0:10

z=(x^2)+(y^2);

M(j,:)=[x,y,z];

j=j+1;

end

end

figure;

surf(M)

Title('3D Plot')

EXPERIMENT 2

clc;

clear all;

close all;

A=input('Enter the first matrix');


B=input('Enter the second matrix');

C=A+B;

D=A-B;

E=A.*B;

F=A./B;

EXPERIMENT 3

clc;

clear all;

close all;

e=input('Enter total no. of student');

for e1=1:e

A(e,:)=input('Enter marks in English');

B(e,:)=input('Enter marks in Maths');

C(e,:)=input('Enter marks in Science');

D(e,:)=(A(e,:)+B(e,:)+C(e,:))/3

if D>60

display('The Student no. "e" has achieved First


Class')
end

if D<40

display('Student no. "e" Student has Failed')

end

end

EXPERIMENT 4

(A)

clc;

clear all;

close all;

syms x y;

S1=3*x-y+2==0;

S2=x+y-1==0;

s3=[S1,S2]

S=solve(s3,[x,y])
(B)

clc;

clear all;

close all;

syms x

e1=cos(3*x)+sin(3*x)-9==0;

S=solve(e1,x)

(C)

Syms x y c

e1=[2*x-3*c*y-5==0,c*x+2*y-7==0];

S=solve(e1,[x y c])

(D)

clc;

clear all;

close all;

syms x y
e1=[3*x^(2)-2*x+y-7==0,x*y+x-5==0];

S=solve(e1,[x y])

(E)

clc;

clear all;

close all;

syms x y z

e=[x+3*y^2 +5*z==19,x+5*sin(y) +7*exp(z)==22,-


3*x+12*y+18*z^(1/2)==56]

S=solve(e,[x y z])

EXPERIMENT 5

(A)

clc;

clear all;

close all;
j=input('Enter a number to determine it factorial=');

i=1

g=1;

while i<j+1

f=i;

g=f*g;

i=i+1

end

(B)

clc;

clear all;

close all;

x=0.5;

g=0;

e=100;

A1=exp(0.5);

j=1;
for i=1:e

f=x^(i-1)/factorial(i-1)

g=g+f;

val(j,:)=g;

if j>=2

ea(j-1,:)=(val(j,:)-val(j-1,:))/val(j,:)

if ea(j-1,:)<=0.05

break

end

end

j=j+1;

end

(C)

clc;

clear all;

close all;

g=0;
i1=20;

i=1;

j=1;

Answer=(pi^4)/90;

ea1=0;

while i<i1

f=(1/i)^4;

g=g+f;

i=i+1;

val(j,:)=g;

A1=val(j,:)-Answer;

if A1==0;

break

end

j=j+1;

end

(D)
clc;

clear all;

close all;

g=0;

x=0.3*pi;

A1=cos(x);

i=input('Enter maximum number for iterations for


given value');

while i>0

f=((-1)^(i))* (x^(2*i))/factorial(2*i);

g=g+f;

i=i-1

val(j,:)=g;

et(j,:)=(A1-g)/A1;

if j>=2

ea(j-1,:)=(val(j,:)-val(j-1,:))/val(j,:);

end

j=j+1;
es=(0.05);

end

EXPERIMENT 6

clear all;

close all;

xl=5;

xu=10;

j=1;

for x=1:100

xr(j,:)=(xl+xu)/2;

fl=-0.5*xl^(2)+2.5*xl+4.5;

fu=-0.5*xu^(2)+2.5*xu+4.5;

fr(j,:)=-0.5*(xr(j,:))^(2)+2.5*xr(j,:)+4.5;

if fr(j,:)*fu<0

xl=xr(j,:);
end

if fr(j,:)*fl<0

xu=xr(j,:);

end

if abs(fr(j,:))<0.00009

break

end

j=j+1;

end

EXPERIMENT 7

(A)

clc;

clear all;

close all;
syms f(x)

f(x)= 2*x^(3)-11.7*x^(2)+17.7*x-5;

x0=3;

j=1;

et=0.0001;

a=diff(f(x))

fa=inline(a);

fb=inline(f(x));

for x=1.5

f1x=fa(x0);

f2x=fb(x0);

xr=x0+(f1x/f2x);

x0=xr;

x1(j,:)=xr;

if j>2

epsa=(x1(j,:)-x1(j-1,:))/x1(j,:);

if epsa<et

break end
end

j=j+1;

end

(B)

clc;

clear all;

close all;

syms g(x)

g(x)=exp(-x);

gin=inline (g(x));

x0=0;

j=1;

for y=1:100

xr= gin(x0);

x1 (j,:)=x0;

if j>2

epsa(j-1,:)=abs ((x1(j,:)-x1(j-1,:))/x1(j,:));
if epsa(j-1,:)<0.001;

break

end

end

xo=xr;

j=j+1;

end

(C)

clc;

clear all;

close all;

syms f(x)

f(x)=sin(x)+cos(1+x^(2))-1;

x0=0;

j=1;

et=0.0001;

a=diff(f(x));
fa=inline(a);

fb=inline(f(x));

fpr x=1:10;

f1x=fa(x0);

f2x=fb(x0);

xr=x0-(f2x/f1x);

x0=xr;

x1(j,:)=xr

if j>2

epsa (j-1,:)=abs ((x1(j,:)-x1(j-1,:))/x1(j,:));

if epsa(j-1,:)<et

break

end

end

j=j+1;

end

EXPERIMENT 8
(A)

clc;

clear all;

close all;

n=3;

c=[3 -0.1 -0.2; 0.1 7 -0.3;0.3 -0.2 10];

b=[7.85 -19.3 71.4];

dett=dett(c);

if dett==0

print('This system is unsolvable because det(c)=0')

else

b=b';

A=[c b];

for j=1:(n-1)

for i=(j+1):n

mult=A(i,j)/A(j,j);

for k=j:n+1;

A(i,k)=A(i,k)-mult*A(j,k);
A;

end

end

x=A(:,n+1)/A(n,n)

end

(B)

clc;

clear all;

close all;

n=3;

c=[3 -0.1 -0.2; 0.1 7 -0.3;0.3 -0.2 10];

b=[7.85 -19.3 71.4];

dett=dett(c);

if dett==0

print('This system is unsolvable because det(c)=0')

else

b=b';
A=[c b];

for j=1:(n-1)

for i=(j+1):n

mult=A(i,j)/A(j,j);

for k=j:n+1;

A(i,k)=A(i,k)-mult*A(j,k);

A;

end

end

end

for i=1:n-1

for j= i+1:n

mult=A (i,j)/A(j,j);

for k=j:n+1

A(i,k)=A(i,k)-mult*A(i,k);

A;

end

end
end

for p=n:-1:1

for r=p

x(p)=A(p,n+1)/A(p,r)

end

end

EXPERIMENT 9

(A)

clc;

clear all;

close all;

f=@(x)6*(cos(x/2)).*(sin(x/2)).^2;

a=0;

b=pi;

n=200;

h=(b-a)/n;

s=1/2*(f(a)+f(b));
for i=1:n-1

s=s+f(a+i*h);

end

A=h*s;

format long

disp(A)

(B)

clc;

clear all;

close all;

f=@x exp(-2.^2);

true=integral(f,0.1);

n=128;

k=n/2;

a=0;

b=1;

h=(b-a)/n;
x=a+h;

sum1= (h/3)*(f(b)+f(a));

sum1=sum1+(4*h/3)*f(x);

for j= 1:n-1

x1=a+(2*j)*h;

x2=a+(2*j+1)*h;

sum1=sum1+(2*h/3)*f(x1)+(4*h/3)*f(x2);

end

error1=abs(true-sum1);

fprintf('Simpsons %d: %0.8f\n', n, sum1);

fprintf('Simpsons Error: %0.8f\n', error1);

You might also like