I have these lines of code:
function f = trick(t,x,M,K)
f = zeros(4,1);
f(1) = x(2);
f(2) = x(3);
Minvneg = -inv(M);
[f(3),f(4)] = Minvneg*K*[x(4) x(5)]';
I'm using this inside of a function called within the ode23 function where M and K are 2x2 matrices. the result of
should give a 2x1 column vector which I need to assign to f(3) and f(4) respectively.
I have tried doing this multiple ways except for making the matrix multiplication happen within double for loops which is terrable.
What is the best way to assign these values.
I think this would be very similar to doing this and it not working.
One thing I tried but didn't work was:
This just doesn't work within the ode23 function
If it helps, here is the code I am using to call this function:
time = (0:.001:22.5)';
M = [1 2; 3 4];
K = [5 6; 7 8];
x0 = [0;0;0;0];
[t1,x]=ode23(@(t1,x) trick(t1,x,M,K), time, x0);