From: Ben H on
Hi,

So I am using the ode solvers for the first time, in this case ode45. I am solving a 2nd order ode and I think I'm making headway with it in simple terms. However, I want to solve it at different 'j' values which correspond to modes, and then sum to find the total effect. So far by using a for loop, I can only get it to give me the answers for the last j value I speculate, ie. 5 in the script below and do not know how to make it use all the j values and sum the effects. Here is a sample of the function file I have, and the code I am working with for the solution:

Function file____________________________________
function xdot = fun(t,x)
%Computes derivatives of two equations
global A B C D d j;
xdot(1) = x(2);
xdot(2) = A*sin(j*pi*t) + B*sin(j*pi*(t-d)) - C*x(2) - D*x(1);
xdot = [xdot(1); xdot(2)];
_______________________________________________

Code so far_______________________________________
global A B C D d epsilon j;
for j = 1:2:5
A = 10;
B = 20;
C = 30;
D = 40*j;
d = 0.1;
[t, x] = ode45('fun', [0, 1], [0, 0]);

q = x(:,1);
qdot = x(:,2);
ft = A*sin(j*pi*t) + B*sin(j*pi*(t-d));
qdotdot = ft - C*qdot - D*q;

M_mu = (-1/12)*(1/j^2).*qdotdot.*sin(j*pi.*t);
end
______________________________________________

Note how will have different sets of values for q, qdot and qdotdot corresponding to each j value.
Ultlimately I want to end up a set of M_mu values which are a summation of each of the individual M_mu values at each j. (As most of you know!) I can't check the values by inputing j = 1 and j = 3 and then adding because the vector of answers has different sizes due to the solver using different step sizes etc.

I hope I have been clear but please ask if you need more info,

Thanks a lot.