Info
This question is closed. Reopen it to edit or answer.
I connected two systems of differential equations into one function file and it gives different values.
2 views (last 30 days)
Show older comments
Hi,
I have this original code which works fine.
Ncycl=100; % - ... Number of cycles
tspan=[0 6*3600];
tchar=cell([1 Ncycl]);
tdis=cell([1 Ncycl]);
ychar=cell([1 Ncycl]);
ydis=cell([1 Ncycl]);
for k=1:Ncycl
if k==1
y0=y0;
else
y0=[ydis{k-1}(end,1:end-1) E0]
end
[tchar{k},ychar{k}]=ode45(@(t,y)VRFBNC(t,y,-I,mode,konst),tspan,y0,options);
y0=[ychar{k}(end,1:end-1) E0];
[tdis{k},ydis{k}]=ode45(@(t,y)VRFBNC(t,y,I,mode,konst),tspan,y0,options);
end
then I connected it together with another function into one file to create only one system of diff equations.
function dz = fun(t,z,I,mode,konst)
Ncell=konst(1);
ncell=Ncell-2;
n1 = 4+4*Ncell+1;
n2 = 4+3*ncell+2;
y = z(1:n1);
T = z(n1+1:n1+n2);
dVRFBNC = VRFBNC(t,y,I,mode,konst);
dteplo = teplo(t,y,T,konst);
dz = [dVRFBNC;dteplo];
end
this is the new for cycle with additional initial conditions
Ncycl=20; % - ... Number of cycles
tspan=[0 6*3600];
tchar=cell([1 Ncycl]);
tdis=cell([1 Ncycl]);
ychar=cell([1 Ncycl]);
ydis=cell([1 Ncycl]);
counter=1;
for k=1:Ncycl
if k==1
z0=z0;
else
z0=[ydis{k-1}(end,1:4+4*Ncell) E0 ydis{k-1}(end,4+4*Ncell+2:end)]
end
[tchar{k},ychar{k}]=ode45(@(t,z)fun(t,z,-I,mode,konst),tspan,z0,options);
z0=[ychar{k}(end,1:4+4*Ncell) E0 ychar{k}(end,4+4*Ncell+2:end)];
[tdis{k},ydis{k}]=ode45(@(t,z)fun(t,z,I,mode,konst),tspan,z0,options);
counter=counter+1;
end
Then somehow it does not give the right values. The weird thing is that at least the original function should produce the same values - however now these values are changing really slow (basically constant). Any ideas? I checked all konstants I added, cannot find out why is not working now.
0 Comments
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!