Hello,(adsbygoogle = window.adsbygoogle || []).push({});

For Euler's Method of Numerical Approximations, my book (Boyce&DiPrima)

gives this algorithm:

Step 1: define f(t,y)

Step 2: input initial values t0 and y0

Step 3: input step size h and number of steps n

Step 4: output t0 and y0

Step 5: for j from 1 to n do

Step 6: k1 = f(t,y)

y = y + h*k1

t = t + h

Step 7: output t and y

Step 8: end

I tried this on Matlab. My code was:

t=input('Enter t0:');

y=input('Enter y0:');

h=input('Enter step size h:');

n=input('Enter number of steps n:');

k1=input('Define f(t,y):');

result=zeros(n,2);

result(1)=t;

result(1,2)=y;

for j=[2:n+1]

k=k1;

y=y+k*h;

t=t+h;

result(j,1)=t;

result(j,2)=y;

end

disp(' t y');

disp(result);

But I realise that my program calculates k1 only for the initial values... How can I change it so that k1 is actually calculated in every turn of for loop?

Thanks.

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab Question

Loading...

Similar Threads - Matlab Question | Date |
---|---|

MatLab function question | Sep 5, 2015 |

Contour question in matlab | Feb 9, 2015 |

Concept and subject of latex and its usage and related questions on latex | Sep 25, 2014 |

Computing question 1st year Engineering-MATLAB | Apr 22, 2014 |

Matlab question: How to pick specific value from column vector | Jan 16, 2014 |

**Physics Forums - The Fusion of Science and Community**