Hi
When i solve a second order differential equation with constant coefficients, i obtained a solution. But when i change these coefficients by the matrix form i have obtained this error:
Error using horzcat. Dimensions of matrices being concatenated are not consistent.
And my new code is a function :
function xdot = equadif(t,x)% Function file for mass with spring and damping.
% Position is first variable, velocity is second variable.
F=[12;23:0];M=[1,0,0;1,3,0;0,0,2];cp = 1.38*10^-9;K = [5,-6,1;-6,2,20;4,2,5];TETA = [1,1,0;2,0,0;1,0,0];C =[2,10,0;5,4,0;1,5,0];R = 10*10^3;A = [zeros(3,3), eye(3,3), zeros(3,1); -K*M^-1, -C*M^-1, TETA*M^-1; zeros(3,3), TETA/cp, -1/(R*cp)];B = [0; M^-1 ; 0];xdot = A*x+B*F;end[t,x]=ode45(@equadif,[0,0.01,0.03],[0,1,0]);plot(t,x(:,1),'b',t,x(:,2),'r',t,x(:,3),'--')
Best Answer