The second approach is the correct one.
In the first approach, you only add 0 to -t * x(1) - exp(t) * x(2) + 3 * cos(2 * t) because xp is preallocated as zeros(3,1). This is obvioulsy incorrect.
Best wishes
Torsten.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!