I'm trying to compute the approximation solution for y′=−2y+2−e^(−4t):0<=t<=5,y(0)=1 but the answer that I get for n=100 intervals is −5.069 which isn't right. What's the issue with my algorithm?

Arnav Heath

Arnav Heath

Open question

2022-08-21

y′=f(t,y) with Euler's Method
I'm trying to compute the approximation solution for
y = 2 y + 2 e 4 t : 0 t 5 , y ( 0 ) = 1
but the answer that I get for n = 100 intervals is −5.069 which isn't right. What's the issue with my algorithm?

valueA = 0;
valueB = 5;
double y0 = 1;
double y1 = 0;
double t = 0;
valueN = 100;
double valueM = 0;

double functionOne = 0;
double h = (valueB-valueA)/valueN;
for (double i = 0; i <= 5.00; i+=h){
valueM = ((-2*y0) + 2 - Math.exp(-4*t));

y1 = y0 + (t * valueM);
y0 = y1;
t += h;

}
return y1;

First Ten Values:
1. 1.0
2. 0.959063462346101
3. 0.9002187652733168
4. 0.8478313902772178
5. 0.8188330413428864
6. 0.8174466603785826
7. 0.8366204005777724
8. 0.8646771827937695
9. 0.8921768293608917
10. 0.9148331832363752
11. 0.9323323583816936

Answer & Explanation

Katelynn Petersen

Katelynn Petersen

Beginner2022-08-22Added 2 answers

With t n + 1 = t n + δ t your algorithm is essentially y ( t n + 1 ) = y ( t n ) + δ t y ( t n ).

I think the incriminated line is
y1 = y0 + (t * valueM);
which should be
y1 = y0 + (h * valueM);
Baylee Atkinson

Baylee Atkinson

Beginner2022-08-23Added 2 answers

Tthanks a lot

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?