Mth643 Paper Code Solution
Mth643 Paper Code Solution
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
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)
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)
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
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
clc
clear all
close all
yprime=@(t,y)2*t;
tspan=[0 5];
y0=0;
[t,y]=ode45(yprime,tspan,y0)
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)
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
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)
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)