Problem 231. Differential equations I
Given a function handle f an initial condition y0 and a final time tf, solve numerically the differential equation
dy/dt = f(y)
for the function y(t) between t=0 and t=tf. Give as a result res=y(tf).
Example:
f = @(x) -x; tf= 1; y0= 1;
=> y(tf) = 1/e = 0.367879441171442
Remarks: aim at a relative precision of around 1e-6. The function is analytic in the interval [0,1].
Solution Stats
Problem Comments
-
5 Comments
As Nikolaos mentioned, the last test needs a fix. The value of 'a' is not transferred into the function handle 'f', and 'a' is just a char (not a value) in 'f'.
The last test case is not broken. When you define an anonymous function that includes variables, those variables are stored along with the function and remain available to it. This is true also when handles to the anonymous function are passed around, or when the variables in question are cleared from memory. See https://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html#f4-71621 .
I am completely lost while solving it, please someone guide me
Solution Comments
Show commentsGroup

M3 Challenge Problem Group
- 20 Problems
- 20 Finishers
- Add two numbers
- Return area of square
- Make the vector [1 2 3 4 5 6 7 8 9 10]
- Calculate Amount of Cake Frosting
- Sum all integers from 1 to 2^n
- Reverse the vector
- Magic is simple (for beginners)
- Solve a System of Linear Equations
- Roll the Dice!
- Chess probability
- Throwing Dice - Will You Be Eaten By The Dragon?
- The Birthday Phenomenon
- Fibonacci sequence
- Monte-Carlo integration
- Make a Plot with Functions
- Differential equations I
- Numerical Integration
- Create initial basic feasible solution for transportation problems - North-West Corner Method
- Create initial basic feasible solution for transportation problems -Minimum Cost Method
- There are 10 types of people in the world
Problem Recent Solvers135
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!