Question

# Q(1) SOLVE A SIMPLE ODE # the ODE, dy/dx + y = x, y(0) =...

# Q(1) SOLVE A SIMPLE ODE

# the ODE, dy/dx + y = x, y(0) = 1 can be analytically solved to get

# the equation y(x) = x + 2*exp(-x) - 1.

# Show that you can use ODEINT to match that performance using pyplot

This is in python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Note: Brother sometimes while uploading on HomeworkLib the indentations change. So, I request you to verify it with screenshot once. This is the link where I have saved the code too

https://trinket.io/python3/8e6278181f

import matplotlib.pyplot as plt
from scipy.integrate import odeint
import numpy as np
def f(x,y):
return x-y;
x = np.linspace(0,2,100);
x0=1
y1=odeint(f, x0, x);
y2=x+2*np.exp(-x)- 1
plt.plot(x,y1);
plt.plot(x,y2);
plt.legend(['ODEINT','Exact']);
plt.show();

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
# Q(1) SOLVE A SIMPLE ODE # the ODE, dy/dx + y = x, y(0) =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT