How to plot a current based on active voltage?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anniken
am 18 Okt. 2023
Kommentiert: Anniken
am 18 Okt. 2023
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 Kommentar
Torsten
am 18 Okt. 2023
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.
Akzeptierte Antwort
Torsten
am 18 Okt. 2023
Bearbeitet: Torsten
am 18 Okt. 2023
i = [100,10,100];
t = [0,0.2,0.4,0.6];
R = 8.314;
F = 9.648e4;
Temp = 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 ;
T = [];
U = [];
u0 = 0;
for j = 1:numel(i)
fun= @(t,u) (i(j)-A_m * ipp_0 * (exp(b_an*F/(R*Temp)*u)-exp(-b_ca*F/(R*Temp)*u)))/C_dl;
tspan = [t(j) t(j+1)];
[Tstep,Ustep] = ode15s(fun,tspan,u0);
T = [T;Tstep];
U = [U;Ustep];
u0 = Ustep(end,:);
end
figure(1)
plot(T,U)
grid on
ifun = @(time) 0;
for j = 1:numel(t)-1
ifun = @(time)ifun(time)+i(j)*(time>=t(j))*(time<t(j+1));
end
for j = 1:numel(T)
iplot(j) = ifun(T(j));
im(j) = A_m*ipp_0*(exp(b_an*F/R/Temp*U(j)) - exp(-b_ca*F/R/Temp*U(j)));
idl(j) = iplot(j) - im(j);
end
figure(2)
plot(T,[iplot;idl;im].')
grid on
Weitere Antworten (1)
Florian Bidaud
am 18 Okt. 2023
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 Kommentare
Florian Bidaud
am 18 Okt. 2023
Bearbeitet: Florian Bidaud
am 18 Okt. 2023
The plots you have inside your function are not of any use for the solving
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


