ode45 with two variables

2 views (last 30 days)
Pavan Kumar
Pavan Kumar on 30 Jan 2015
Commented: Torsten on 30 Jan 2015
Hii Friends,
I have a variable delk which is [1*170001] matrix
I defined coupled equations as shown.
dB = zeros(3,170001); % a column vector
dB(1) = i*R*GammaL*B(3)*conj(B(2)).*exp(i.*delk*Z1); dB(2) = i*S*GammaL*B(3)*conj(B(1)).*exp(i.*delk*Z1); dB(3) = i*GammaL*B(1)*B(2).*exp(-i.*delk*Z1);
[Z1,B] = ode45(@(Z1,B) DFG789(Z1,B,delk),[0 3],[(0.1) 0 1]); plot3(delk,abs(B(:,1)).^2);
when i run the code i get the following errors. Any Suggestions?
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in DFG789 (line 41) dB(1) = i*R*GammaL*B(3)*conj(B(2)).*exp(i.*delk*Z1);
Error in @(Z1,B)DFG789(Z1,B,delk)
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in DFG7891 (line 28) [Z1,B] = ode45(@(Z1,B) DFG789(Z1,B,delk),[0 3],[(0.1) 0 1]);
  2 Comments
Torsten
Torsten on 30 Jan 2015
You still don't get it.
In the assignments
dB(1) = i*R*GammaL*B(3)*conj(B(2)).*exp(i.*delk*Z1);
dB(2) = i*S*GammaL*B(3)*conj(B(1)).*exp(i.*delk*Z1);
dB(3) = i*GammaL*B(1)*B(2).*exp(-i.*delk*Z1);
dB(1), dB(2), dB(3) are scalars, while the expressions on the right-hand side are vectors of length 1700001.
You could repair this by setting
dB(1:170001)=...
dB(170002:340002)=...
dB(340002:510003)=...
and by making the vector of initial values a 1x510003 - vector, but do you really want ODE45 solve 510003 ODEs simultaneously ? I think this is not a good idea.
Best wishes
Torsten.
Torsten
Torsten on 30 Jan 2015
Your assignments would read
dB(1:170001)=i*R*GammaL*B(340003:510003)*conj(B(170002:340002)).*exp(i.*delk*Z1);
dB(170002:340002)=i*S*GammaL*B(340003:510003)*conj(B(1:170001)).*exp(i.*delk*Z1);
dB(340003:510003)=i*GammaL*B(1:170001).*B(170002:340002).*exp(-i.*delk*Z1);
and the initial condition vector
y0=zeros(510003);
y0(1:170001)=0.1;
y0(170002:340002)=0;
y0(340003:510003)=1;
Best wishes
Torsten.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!