Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Name: Aravind Karuppusamy

Problem 1:

Solution:
%interp1
x = [1 5 10 20 40 60 80 100 150 200 250 300 400 500];
y = [0.9967 0.9832 0.9660 0.9314 0.8625 0.7977 0.7432 0.7084 0.7180 0.7986 0.9000
1.0068 1.2232 1.4361 ];
xi = linspace(1,500);
yspl = interp1(x,y,xi,'spline');
plot(xi,yspl,x,y,'o');
hold on
yi = interp1(x,y,275,'spline');
plot(275,yi,'x')
%polyfit
p = polyfit(x,y,3);
y1 = polyval(p,xi);
plot(xi,y1)
ypf = polyval(p,275);
plot(275,ypf,'x')
Name: Aravind Karuppusamy

Graph:
Name: Aravind Karuppusamy

Problem 2:

Solution:
function xi = TrigPoly_mod(x,m,t1,tN,ti)
N=length(x);
h=2*pi/N; s=0:h:2*pi-h; s=s';
a=zeros(m,1);
b=a;

for i=1:m
a(i)=x*cos(i*s);
b(i)=x*sin(i*s);
end

a=2*a/N; b=2*b/N; a0=sum(x)/N;

if N== 2*m
a(m)=a(m)/2;
end

ss=linspace(0,2*pi*(N-1)/N,500);
xx= a0 + a(1)*cos(ss)+b(1)*sin(ss);

for i=2:m
xx=xx + a(i)*cos(i*ss)+b(i)*sin(i*ss);
end

t=N*((tN-t1)/(2*pi*(N- 1)))*s+t1;
tt= N*((tN-t1)/(2*pi*(N- 1)))*ss+t1;

ss1=((ti-t1)*(N- 1)*2*pi)/(N*(tN-t1));
xi= a0 + a(1)*cos(ss1)+b(1)*sin(ss1);

for i=2:m
xi = xi+ a(i)*cos(i*ss1)+b(i)*sin(i*ss1);
end ;
plot(tt,xx,t,x,'o',ti,xi,'x')
Name: Aravind Karuppusamy

Output:
>> x=[0.9 1 -1 -0.8 0.9 1];

>> xi = TrigPoly_mod(x,2,1,2.5,2)

xi =

-0.2049

Graph:
Name: Aravind Karuppusamy

Problem 3:

Solution:
function I = Gauss_Quad(f,a,b,n)
syms x s;
sg1 = ((b-a)*(x+1)/2)+a;
dsg1= diff(sg1,x,1);
func1(x) = f(sg1)*dsg1;
for i = 1:n
P(i) = (diff((x^2-1)^i,i))/((2^i)*factorial(i));
t=solve(P(i));
end
g=double(t);
z=sort(g);
v=sort(z);
for i=1:n
tp1=1;
for j=1:n
if j~=i
tp1 = tp1* (x - z(j))/(z(i)-z(j));
cc(i)= (int(tp1,x,-1,1));
end
end
end
temp =0;
C=double(cc);
for i=1:n
temp = temp + C(i)*func1(z(i));
end
I = double(temp);

Output:
>> I = Gauss_Quad(@(x)exp(-x)*x^(1/3),1,6,8)

I = 0.4486 + 0.0000i

>>format long

>> I

I = 0.448615700163669 + 0.000000000000000i

You might also like