How to plot a current based on active voltage?
이전 댓글 표시
I am to plot a current line in a graphs based on a active voltage. When I plot it, 200+ graphs appear and i wonder if maybe it is a mistake to not include it as an array, but cant quite figure it out. Can anybode please help?:)
tspan = [0 0.5];
R = 8.314;
F = 9.648e4;
T = 80 + 273.15; %Conductivity reference temperature
ipp_0 = 0.67e-4;
A_m = 232;
b_ca = 0.55 ;
b_an = 1-b_ca ;
C_dl = 3.5e-2*A_m ;
u0 = 0;
ipp_1 =0;
[T,U] = ode15s(@(t,u) u_act(t,u,A_m,ipp_0,b_an,F,R,T,b_ca,C_dl),tspan,u0);
plot(T,U)
%im = A_m*ipp_0*(exp(b_an*F/R/T*U) - exp(-b_ca*F/R/T*U));
%ipp = (idl+im)/A_m
function i_ret = i(t)
if t< 0.2
i_ret = 100;
elseif t < 0.4
i_ret = 10;
else
i_ret = 100;
end
end
function dudt = u_act(t,u,A_m,ipp_0,b_an,F,R,T,b_ca,C_dl)
im = A_m*ipp_0*(exp(b_an*F/R/T*u) - exp(-b_ca*F/R/T*u));
idl = i(t) - im;
dudt = idl/C_dl;
ipp = (idl+im)/A_m;
figure
plot(T, ipp)
end
It is supposed to look something like this, but we are to find i_pp which is i/A_m.

댓글 수: 1
Torsten
2023년 10월 18일
If differential equations have discontinuous parameters (like "i" in the above case), one should restart the optimizer with the solution obtained so far at the points of discontinuity instead of integrating over. That's why I arranged the code the way I did.
채택된 답변
추가 답변 (1개)
Well you have a plot inside your u_act function, which is gonna be called at each calculation step in ode15s.
If you remove them you get the plot you want
tspan = [0 0.5];
R = 8.314;
F = 9.648e4;
T = 80 + 273.15; %Conductivity reference temperature
ipp_0 = 0.67e-4;
A_m = 232;
b_ca = 0.55 ;
b_an = 1-b_ca ;
C_dl = 3.5e-2*A_m ;
u0 = 0;
ipp_1 =0;
[T,U] = ode15s(@(t,u) u_act(t,u,A_m,ipp_0,b_an,F,R,T,b_ca,C_dl),tspan,u0);
plot(T,U)
%im = A_m*ipp_0*(exp(b_an*F/R/T*U) - exp(-b_ca*F/R/T*U));
%ipp = (idl+im)/A_m
function i_ret = i(t)
if t< 0.2
i_ret = 100;
elseif t < 0.4
i_ret = 10;
else
i_ret = 100;
end
end
function dudt = u_act(t,u,A_m,ipp_0,b_an,F,R,T,b_ca,C_dl)
im = A_m*ipp_0*(exp(b_an*F/R/T*u) - exp(-b_ca*F/R/T*u));
idl = i(t) - im;
dudt = idl/C_dl;
ipp = (idl+im)/A_m;
end
댓글 수: 3
Anniken
2023년 10월 18일
Florian Bidaud
2023년 10월 18일
편집: Florian Bidaud
2023년 10월 18일
The plots you have inside your function are not of any use for the solving
Anniken
2023년 10월 18일
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


