ODE Solver into a 3D Array

조회 수: 5 (최근 30일)
Dean Culver
Dean Culver 2015년 6월 18일
댓글: Dean Culver 2015년 6월 18일
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!

채택된 답변

Jan
Jan 2015년 6월 18일
[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.
  댓글 수: 1
Dean Culver
Dean Culver 2015년 6월 18일
Fantastic! Thanks for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by