ExampleTrapzodial Law
clc
clear
% %Trapezodial Rule
x0=7;
Length=7;
number_of_points=70;
dx=Length/number_of_points;
number_of_sections=number_of_points-1;
%Generating the number of points
N=number_of_points;
%For a case starting from the center of coordanites, this is the absoulute
%value for the node number
xx(1)=0;
%This is just a counter relating to where the process starts
for i=1:N-1
xx(i+1)=xx(i)+1;
end
%This calculates the coordanites of the studied nodes in the x direction
for i=1:N;
x(i)=xx(i)*dx+x0;
end
%This calculates the coordanites of the studied nodes in the y direction
%acoording to the studied function
for i=1:N;
y(i)=1/(1+x(i)^2);
end
for i=1:N;
if (i==1) | (i==N)
a(i)=y(i);
elseif (i>1)
b(i)=y(i);
end
end
b(N)=0;
aa=sum(a(:));
bb=sum(b(:));
Area=0.5*dx*(aa+2*bb);
plot(x,y)
grid on
title('The Studied Area')
figure(1)
clear
% %Trapezodial Rule
x0=7;
Length=7;
number_of_points=70;
dx=Length/number_of_points;
number_of_sections=number_of_points-1;
%Generating the number of points
N=number_of_points;
%For a case starting from the center of coordanites, this is the absoulute
%value for the node number
xx(1)=0;
%This is just a counter relating to where the process starts
for i=1:N-1
xx(i+1)=xx(i)+1;
end
%This calculates the coordanites of the studied nodes in the x direction
for i=1:N;
x(i)=xx(i)*dx+x0;
end
%This calculates the coordanites of the studied nodes in the y direction
%acoording to the studied function
for i=1:N;
y(i)=1/(1+x(i)^2);
end
for i=1:N;
if (i==1) | (i==N)
a(i)=y(i);
elseif (i>1)
b(i)=y(i);
end
end
b(N)=0;
aa=sum(a(:));
bb=sum(b(:));
Area=0.5*dx*(aa+2*bb);
plot(x,y)
grid on
title('The Studied Area')
figure(1)
Newton Raphson
clc
clear
x1=4;
x2=5;
N=50000;
dx=(x2-x1)/N;
j=-1;
for i=1:N;
j=j+1;
x(i)=j*dx+x1;
end
for i=1:N;
y(i)=(x(i))^2-5*x(i)+2;
yp(i)=2*x(i)-5;
a(i)=y(i)/yp(i);
end
xx=0;
for i=1:N
xx=xx+x(i)-a(i);
end
x'
%plot(x)
plot(y)
clear
x1=4;
x2=5;
N=50000;
dx=(x2-x1)/N;
j=-1;
for i=1:N;
j=j+1;
x(i)=j*dx+x1;
end
for i=1:N;
y(i)=(x(i))^2-5*x(i)+2;
yp(i)=2*x(i)-5;
a(i)=y(i)/yp(i);
end
xx=0;
for i=1:N
xx=xx+x(i)-a(i);
end
x'
%plot(x)
plot(y)
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com