0% found this document useful (0 votes)
37 views4 pages

Mth643 Paper Code Solution

Uploaded by

saminarani4595
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)
37 views4 pages

Mth643 Paper Code Solution

Uploaded by

saminarani4595
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/ 4

𝑛

3 k
Q1 find sum = ∑ (x )
𝑘=1

clear all
clc
close all
n=12;
k=1:n;
x=4;
for i=1:length(k);
sum=(3/x)^k(i);
end
disp(sum)

Q2 Newton question
function [x] = Newton(f,fd,x0,n);
f=@(x)x^3+x;
fd=@(x)3*x^2+1;
x0=2;
x=x0;
n=4;
for k=1:n;
x=x-f(x)/fd(x)
end
end

Q3 simpson 1/3 rule

f=@(x)sqrt(x);
a=0;
b=5;
n=18;
h=(b-a)/n;
sum1=0;
sum2=0;
for k=1:n-1;
x(k)=a+k*h;
if (rem(k,2)==0);
sum1=sum1+f(x(k));
else
sum2=sum2+f(x(k));
end
end
Area=h/3*(f(a)+f(b)+2*sum1+4*sum2)

Q4 simpson 3/8 rule

f=@(x)sqrt(x);
a=0;
b=5;
n=18;
h=(b-a)/n;
sum1=0;
sum2=0;
for k=1:n-1;
x(k)=a+k*h;
if (rem(k,3)==0);
sum1=sum1+f(x(k));
else
sum2=sum2+f(x(k));
end
end
Area=3*h/8*(f(a)+f(b)+2*sum1+3*sum2)

Q5 Trapezoidal rule

clear all
close all
clc
f=@(x)x^4;
a=0;
b=2;
n=6;
h=(b-a)/n;
sum=0;
for k=1:n-1;
x(k)=a+k*h;
y(k)=f(x(k));
sum=sum+y(k);
end
Area=h/2*(f(a)+f(b)+2*sum)

Q6 factorial using for loop

a=input('Emter a number')
fact=1;
if a<0;
fprintf('The numbe is negative')
else
for i=1:a;
fact=fact*i
end
end

Q7 factorial using while loop

clear all
clc
close all
n=4;
f=n;
while n>1;
n=n-1;
f=f*n;
end
disp(f)
𝟐 𝟐
Q8 calculate Riemann sum ∫𝟎 𝒆𝒙 𝒅𝒙 for n=20

clc
clear all
close all
f=@(x)exp(x^2);
a=0;
b=2;
n=20;
h=(b-a)/n;
value=0;
for k=1:n;
x(k)=a+k*h;
value=value+f(x(k));
end
R=value*h

Q9 Sum and Prod

function [ sum prod ] = examquestion( s,p )


clc
clear al
close all
s=input('s')
p=input('p')
sum=s+p
prod=s*p
end

Q10 Ode45 command

clc
clear all
close all
yprime=@(t,y)2*t;
tspan=[0 5];
y0=0;
[t,y]=ode45(yprime,tspan,y0)

Q11 Solve differential equation by dsolve command

clc
clear all
close all
syms y(t)
ode=diff(y,t)+5*y==12;
cond=y(0)==10;
solve=dsolve(ode,cond)
Q12 solve system of linear equation by solve command

clc
clear all
close all
equ1='2*x+y+z=2';
equ2='-x+y-z=3';
equ3='x+2*y+3*z=-10';
[x,y,z]=solve(equ1,equ2,equ3)

Q13 solve system of linear equation

clc
clear all
close all
A=[2 1 1;-1 1 -1;1 2 3];
B=[2;3;-10];
C=inv(A);
solve=C*B

Q14 Write argument matrix and find rref

clc
clear all
close all
A=[8 1 6;3 5 7;4 9 2]
b=[1;1;1]
Ab=[A b]
solve=rref(Ab)

Q15 Matrix multiplication

clc
clear all
close all
A=sym([3/11 2/5 4/7;2/3 4/5 6/7;7/9 8/6 9/4])
B=sym([1/3 8/9 4;2/9 3/7 9/6;6 7/4 5/7])
mult=A*B
iver=inv(A)

You might also like