0% found this document useful (0 votes)
17 views

Euler

The Euler Method program uses numerical integration to approximate the solution to a first-order differential equation. The program takes in an equation, initial and final x values, and step size h. It then calculates successive y values by iterating the equation from the initial to final x. A plot of x vs y is displayed along with the input equation.

Uploaded by

qamar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Euler

The Euler Method program uses numerical integration to approximate the solution to a first-order differential equation. The program takes in an equation, initial and final x values, and step size h. It then calculates successive y values by iterating the equation from the initial to final x. A plot of x vs y is displayed along with the input equation.

Uploaded by

qamar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Euler Method

Program:
a=input('Enter your equation in terms of variable x:','s');
xi=input('Enter the initial limit of x:');
xf=input('Enter the final limit of x:');
h=input('Enter value of h:');
y(1)=1;
n=(xf/h);
x(1)=xi;
f=inline(a);
for i=1:(n+1)
fprintf('y(%f)= %f\n',x(i),y(i));
y(i+1)=y(i)+f(x(i),y(i))*h;
x(i+1)=x(i)+h;

end

plot(x,y);
xlabel('x');
ylabel('y');
title('Euler Method');
fprintf('function:%s',a);

Result 1:
>> euler
Enter your equation in terms of variable x:(1+2*x)*(y^0.5)
Enter the initial limit of x:0
Enter the final limit of x:1
Enter value of h:0.25
y(0.000000)= 1.000000
y(0.250000)= 1.250000
y(0.500000)= 1.669263
y(0.750000)= 2.315263
y(1.000000)= 3.266262
function:(1+2*x)*(y^0.5)>>
Result 2:

>> euler
Enter your equation in terms of variable x:y*(t^2)-1.5*y
Enter the initial limit of x:0
Enter the final limit of x:2
Enter value of h:0.5
y(0.000000)= 1.000000
y(0.500000)= 0.250000
y(1.000000)= 0.093750
y(1.500000)= 0.070313
y(2.000000)= 0.096680
function:y*(t^2)-1.5*y>>

Result:

>> euler
Enter your equation in terms of variable x:y*(sinx^3)
Enter the initial limit of x:0
Enter the final limit of x:3
Enter value of h:0.1
y(0.000000)= 1.000000
y(0.100000)= 1.000000
y(0.200000)= 1.000100
y(0.300000)= 1.000900
y(0.400000)= 1.003603
y(0.500000)= 1.010026
y(0.600000)= 1.022651
y(0.700000)= 1.044740
y(0.800000)= 1.080575
y(0.900000)= 1.135900
y(1.000000)= 1.218707
y(1.100000)= 1.340578
y(1.200000)= 1.519009
y(1.300000)= 1.781494
y(1.400000)= 2.172888
y(1.500000)= 2.769128
y(1.600000)= 3.703709
y(1.700000)= 5.220748
y(1.800000)= 7.785702
y(1.900000)= 12.326323
y(2.000000)= 20.780948
y(2.100000)= 37.405707
y(2.200000)= 72.047133
y(2.300000)= 148.762920
y(2.400000)= 329.762764
y(2.500000)= 785.626809
y(2.600000)= 2013.168698
y(2.700000)= 5551.514001
y(2.800000)= 16478.559010
y(2.900000)= 52652.291747
y(3.000000)= 181065.966089
function:y*(sinx^3)>>

You might also like