Several Examples on Solving ODEs
clc
clear
N=10;
x0=1;
L0=1.5;
L=L0+x0;
dx=L/N;
y(1)=0.1;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(y(i)*x(i))+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = y*x';
y=dsolve(eqn1,'y(1)=0.1','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
clear
N=10;
x0=1;
L0=1.5;
L=L0+x0;
dx=L/N;
y(1)=0.1;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(y(i)*x(i))+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = y*x';
y=dsolve(eqn1,'y(1)=0.1','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
clc
clear
N=20;
x0=1;
L0=10;
L=L0+x0;
dx=L/N;
y(1)=0;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(5*x(i)+3)+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = 5*x+3';
y=dsolve(eqn1,'y(1)=0','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
clear
N=20;
x0=1;
L0=10;
L=L0+x0;
dx=L/N;
y(1)=0;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(5*x(i)+3)+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = 5*x+3';
y=dsolve(eqn1,'y(1)=0','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
clc
clear
N=10;
x0=1;
L0=1;
L=L0+x0;
dx=L/N;
y(1)=0;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(2*x(i)*y(i)+x(i))+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = 2*x*y+x';
y=dsolve(eqn1,'y(1)=0','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
clear
N=10;
x0=1;
L0=1;
L=L0+x0;
dx=L/N;
y(1)=0;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(2*x(i)*y(i)+x(i))+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = 2*x*y+x';
y=dsolve(eqn1,'y(1)=0','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
clc
clear
N=10;
x0=1;
L0=1;
L=L0+x0;
dx=L/N;
y(1)=0;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(2*x(i)*y(i)+x(i))+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = 2*x*y+x';
y=dsolve(eqn1,'y(1)=0','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
clear
N=10;
x0=1;
L0=1;
L=L0+x0;
dx=L/N;
y(1)=0;
x(1)=x0;
x=linspace(x0,L,N);
for i=1:N-1;
y(i+1)=dx*(2*x(i)*y(i)+x(i))+y(i);
end
plot(x(:),y(:))
grid on
hold on
eqn1 = 'Dy = 2*x*y+x';
y=dsolve(eqn1,'y(1)=0','x')
x=linspace(x0,L,N);
z=eval(vectorize(y));
plot(x,z,'-*')
title('Comparison Between Two Numerical Solutions')
xlabel('X')
ylabel('Y')
legend('Numerical Solution','Numerical Matlab Solution')
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com