ODE Solver into a 3D Array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dean Culver
el 18 de Jun. de 2015
Comentada: Dean Culver
el 18 de Jun. de 2015
Hello all! I'm trying to solve a structural vibration problem using ode113. Its outputs are time and a 2D matrix with displacements of the various modal coordinates. However, I'm trying to do an ensemble average of responses for various harmonic inputs, so I'm looping through ode113 "Nsig" times, where Nsig is the number of harmonic inputs I'm using. Right now, my script looks like a monster, using way too many instances of "eval" to create and analyze the variable sets that I need to extract the ensemble averages. The line that I really need help with is:
eval(['[t,ass' num2str(j) ']=ode113(@(t,ass' num2str(j) ')nlsmsysf(t,ass' num2str(j) ',Mm,M0,ks,zmv,alpha,nv,mv,omegmv,lx,ly,x0,y0,xF,yF,T,tss,omegmin,omegmax,Ar,phir),tspan,a0);'])
This is inside of a "for" loop bounded from 1:j. It works, but it's clumsy and slow, especially if I'm running 30 signals or large amounts of data. What I'd like to do is:
[t,ass(:,:,j)]=ode113(@(t,ass)nlsmsysf(t,ass(:,:,j),Mm,M0,ks,zmv,alpha,nv,mv,omegmv,lx,ly,x0,y0,xF,yF,T,tss,omegmin,omegmax,Ar,phir),tspan,a0);
This is also inside of the same for loop. It works for the first iteration, but the second time around, I get an "index exceeds matrix dimensions" error. Anybody see a fix? Thank you so much for your help!
0 comentarios
Respuesta aceptada
Jan
el 18 de Jun. de 2015
[t,ass(:,:,j)] = ode113(@(t,ass)nlsmsysf(t,ass(:,:,j), ...
Now "ass(:,:,j)" appears on the right hand side and the left hand side. But the error message might mean, that "ass(:,:,j)" is not existing, when the code tries to use it.
But in the ugly EVAL method (you are right! Avoid EVAL strictly! There is a better solution in every case), you have this (with evaluated EVAL):
[t,ass2] = ode113(@(t,ass2)nlsmsysf(t,ass2, ...
Now "ass2" inside the anonymous function is the name of the variable, and not the variable on the left hand side. So try this:
[t, ass(:,:,j)] = ode113(@(t,ass) nlsmsysf(t,ass, ...
without "(:,:,j)" on the left hand side. Or to reduce the confusion:
[t, ass(:,:,j)] = ode113(@(a,b) nlsmsysf(a,b, ...
Note that the name of the variables do not matter inside the anonymous function.
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!