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
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.

댓글을 달려면 로그인하십시오.

 채택된 답변

Torsten
Torsten 2023년 10월 18일
편집: Torsten 2023년 10월 18일
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

댓글 수: 1

Anniken
Anniken 2023년 10월 18일
This is really clever and i feel like its above my level of expertise in matlab and will try to understand the complex code you have provided! I am truly grateful for your help:))

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Florian Bidaud
Florian Bidaud 2023년 10월 18일
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
Anniken 2023년 10월 18일
But we need to use the solution gived from the plot in dudt function? So we kind of need to collect the results from function dudt and implement them in maybe antoher function which plots the current ipp in regards to the time(x-axis) while take into consideration the function values.
Florian Bidaud
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
Anniken 2023년 10월 18일
Yeah i should remove it. But do you know how i can plot the ipp based on the u_act and time?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2023년 10월 18일

댓글:

2023년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by