why is it takes so much to calculate this function ?
1 view (last 30 days)
Show older comments
tomer polsky on 26 Dec 2019
Answered: Roshni Garnayak on 8 Jan 2020
hi I have this code that describes soltion of ODE . I am using Euler method for solveing first order first degree of ODE .
the problem is that for some reason ,this function takes a lot of time . and when I am ploting the resluts . it gets stuck why is that ?
%%% values for calcalution of I1_desire
U=values_of_circuit.U; %% Vin
R=values_of_circuit.R; %% Rload
C2=values_of_circuit.C2; %% Capacitance of the output capsitor
C1=values_of_circuit.C1; %% Capacitance of the first capsitor
L1=values_of_circuit.L1; %% Inductnce of inductor 1
L2=values_of_circuit.L2; %% Inductnce of inductor 2
R_C2=values_of_circuit.R_C2; %% Resistence of the C2
R_C1=values_of_circuit.R_C1; %% Resistence of the C1
R1=values_of_circuit.R1; %% Resistence of the L1 (also this parmater is used for the half idial simulation )
R2=values_of_circuit.R2; %% Resistence of the L2
R_diode=values_of_circuit.R_diode; %% Resistence of diode
V_diode=values_of_circuit.V_diode; %% Forward volatge across the diode
alpha_1=Duty_Cycle_Parmeters.alpha_desire; %% alpha desire for the desried output voltage
t_ode=Run_Time_Values.t_ode; %% end time of the running simulation
Rohav_H=1; %% width of Histers window
t_run_B_C=t_ode; %% run time for the function
t_delta_B_C=1000e-9; %% step size of the euler's therom
number_of_samples_B_C=round(t_run_B_C/t_delta_B_C); %%calculation of number of samples
S_switch=zeros(1,number_of_samples_B_C);%%S_switch= array of zeros with size of number_of_samples_B_C
x=zeros(4,number_of_samples_B_C); %%x=array of zeros with size of number_of_samples_B_C
x(:,1)=[ 0 0 0 0]';%% starting condtion
V_out_Boundery_Control=zeros(1,number_of_samples_B_C); %%V_out_Boundery_Control=array of zeros with size of number_of_samples_B_C
A_total=A_a* Switch_State+A_b* not(Switch_State);
and if I plot the resluts ,the plot takes a lot of time to be ready , and also works very slow when I want to zoom in .
plot(B_C_with_delay_Eulers_Results.t_with_delay,B_C_with_delay_Eulers_Results.x_BC_with_delay(3,:),'-- red d');
plot(B_C_with_delay_Eulers_Results.t_with_delay,0.5*B_C_with_delay_Eulers_Results.Switch_BC_with_delay,'-- blue d');
plot(B_C_with_delay_Eulers_Results.t_with_delay,0.5*B_C_with_delay_Eulers_Results.test,'-- magenta d');
plot(B_C_with_delay_Eulers_Results.t_with_delay,1*I_1_desired*ones(size(B_C_with_delay_Eulers_Results.t_with_delay)),' black ','linewidth',3); %% plot--> of boundery limit
legend('I_1','Switch with delay ','test of the delay','boundery limit ');
John D'Errico on 26 Dec 2019
There is a reason why they only teach Euler's method to beginning students, but never recommend it as a method for later use. As methods go, it is usually crapola.
Roshni Garnayak on 8 Jan 2020
You can use the MATLAB Profiler to check which part of the code is consuming more time to run. Once you figure that out, you can optimize that part of the code.
To know more about the MATLAB Profiler, refer to the following link:
Find more on Power and Energy Systems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!