I downloaded your code and saved it as coupledMasses1DextForce0.m. When I ran it, I got an error message about the function definition:
Undefined function or variable 'testode_2D'. ...
This error occurs because the function name in the declaration at the end of the script is "testodeF_2D", which has "F" in it. I removed the "F" from the function name at the end of the script, and I ran the script again. I got a new error message:
Error using interp1>reshapeAndSortXandV (line 424)
X and V must be of the same length. ...
Error in coupledMasses1DextForce0>testode_2D (line 86) ...
This happens because you have defined f so that it is 50x1. It should be 2x25 (given your choice for ft, which, as I explain below, is not a good choice - but we'll get to that later). Thefore I change
and re-run. Now I get a new error:
Incorrect dimensions for matrix multiplication. ...
Error in coupledMasses1DextForce0>testode_2D (line 87)
This happens because interp1() returns a row vector for interpolated f, but you need a column vector. Therefore we change
and re-run. Now the program runs to completion, with no errors. This is good!
However, the figure that is generated shows not data, and the time range is not 0 to 4 seconds as we expect it to be. Here is a screenshot of the figure:
What is going on?
For one thing, the choice of the vector of times, ft, is not good. You have:
However, you also specify a time span of 0 to 4 for integration. Therefore your range for ft should be 0 to 4 (or wider). Also, you specify 25 points between t=1 and t=4, i.e. about 8 Hz sampling. That is not enough, because your sine wave frequency is 5 Hz. You shoudl sample at more than twice the sine wave frequency. I suggest
which gives 50 samples per second from t=0 to t=4. This is 10 samples per cycle, which is enough for a fairly smooth re-creation of the sinusoid by interpolation.
I am also deleting the 'Fontsize' instructions in the plotting section, since the labels are not displaying well. Then re-run. The plot is not much different. The reason is that the array of results, ysol(), is all NaNs. Why?
To be continued.