Syntax question - renaming a variable
이전 댓글 표시
Dear Community,
I have a very basic syntax question:
I defined up=y(1) because I wish that matlab evaluates the diff(up) for every k and the syntax diff(y(1)) doesn't seem to work.
However I realized that after solving that upALL=cat(1,upALL,up) and the first column of yALL (so yALL(1)) don't show the same values even though I expect them to be strictly same. Also I expect that yALL and upALL return the same number of values over the same interval LALL.
Any hint?
Thanks!!
Ld=2.8; Ld1=3.4; Lv=1.3; Lv1=1.5;
s=125; LPool1=zeros(s,1);
for k=1:numel(LPool1)
if rem(k,2)==1 && k<98
LPool1(k)= (Ld+Lv)*(k-1)/2;
elseif rem(k,2)==1 && k>97
LPool1(k)= (Ld+Lv)*(97-1)/2+(Ld1+Lv1)*(k-97)/2;
elseif k<98
LPool1(k)=(k/2)*Ld+(k/2-1)*Lv;
elseif k>97
LPool1(k)=(96/2)*Ld+(96/2)*Lv +((k-96)/2)*Ld1+((k-96)/2-1)*Lv1;
end
end
LPool=LPool1.';
y0=[1.1,40];
LALL=[];yALL=[];upALL=[];
for k=1:numel(LPool)-1
[L,y]=ode45(@(L,y) myODE(L,y),LPool(k:k+1),y0); y0=y(end,:);
up=y(1);
upALL=cat(1,upALL,up); LALL=cat(1,LALL,L); yALL=cat(1,yALL,y);
end
function dy = myODE(L,y)
global u; u=y(1);
global Tp; Tp=y(2);
dudL = myODE1(L,u,Tp);
dTpdL = myODE2(L,u,Tp);
dy = [dudL;dTpdL];
end
function dudL = myODE1(L,u,Tp)
dudL=5*u+3*Tp;
end
function dTpdL=myODE2(L,u,Tp)
dTpdL=12*u+25*Tp;
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!