Can't solve ODE with array instead of constant
3 Comments
The code is strange:
A = importdata('Realroad.m');
It is unusual, that an M-file contains data, which can be imported. It is not clear, where ht is coming from. In consequence I cannot run your code. The current description "it won't solve the problem" does not allow to understand, what you observe. Do you get an error message? If so, post a copy of the complete message.
Answers (1)
Do not solve an integration for a large set of parameters at once, because this reduces the processing speed and accuracy of the result. Remember, that the step-size controller of the integrator chooses the time steps such, that the effect of local discretization errors and the accumulated rounding error is minimized. Performing the integration with a set of different parameters does not allow to run the integration at the optimal trajectory for each parameter.
To run ODE for a set or different parameters, call it in a loop and vary the parameters. Using an anonymous function for the actual integration is not useful: slower and harder to debug. Use a standard function instead:
function dx = fcn(t, x, ch, m, cs, kh, hx, ht, M)
dx = [x(3); ...
x(4);
(-ch/m)*x(3) + (ch/m)*x(4) - (cs/m)*x(3) - (kh/m)*x(1) + ...
(kh/m)*x(2) - (ks/m)*x(1) + hx.*(ks/m) + ht.*(cs/m); ...
(ch/M)*x(3) - (ch/M)*x(4) + (kh/M)*x(1) - (kh/M)*x(2)];
end
Now the loop:
for hxi = 1:numel(hx)
for hti = 1:numel(ht)
fcnP = @(t,x) fcn(t, x, ch, m, cs, kh, hx(hxi), ht(hti), M);
[t,xa] = ode45(fcnP, 0:0.1:100, [0 0 0 0]);
...
end
end
1 Comment
Categories
Find more on Polynomials in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!