Why I have this error: "Error using ==> minus Matrix dimensions must agree."
Show older comments
y0_d=[0; 0.2; -0.1];
dom_d=[0,3];
[xval_d,yval_d]=ode45('ex3_d_f',dom_d,y0_d)
And this is my funtion file:
function dy=ex3_d_f(x,y,z,t)
dy=zeros(3,1);
dy=[y-2.*z+sin(t)-2.*x; x+2.*z-cos(t)-2.*y; 3*x-3*y+5.*z];
Please correct my code
1 Comment
The ode45 documentation explains that "The function dydt = odefun(t,y), for a scalar t and a column vector y, must return a column vector dydt...". Does this match your function definition? (hint: no, your function has four inputs).
Answers (1)
Cris LaPierre
on 12 Apr 2021
0 votes
You haven't given us all your inputs, so we can only guess.
The error you are getting suggests at least one of the following is true
- sin(t) and 2.*x are not the same size
- 2.*z and cos(t) are not the same size
- cos(t) and 2.*y are not the same size
- or 3*x and 3*y are not the same size
When you subtract matrices, they must have the same size, or one must be a scalar.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!