Effacer les filtres
Effacer les filtres

ode23, too slow

3 vues (au cours des 30 derniers jours)
Gloria
Gloria le 3 Juin 2022
Commenté : Steven Lord le 3 Juin 2022
It takes a long time to solve the code. Is it because the code is reading data from a.dat file? How can I make it go faster? It slows down even more as time increases and the time step gets smaller.
  2 commentaires
Walter Roberson
Walter Roberson le 3 Juin 2022
https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Walter Roberson
Walter Roberson le 3 Juin 2022
I also suspect that you have a stiff system and should try ode23s

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 3 Juin 2022
Reading the files in each iteration is a very time-consuming method. Do this once only and store the values in a persistent variable:
function [du] = mart(t,u)
persistent Fyr FyrPi Fzr FzrPi Mxr MxrPi f
if isempty(Fyr)
Fyr = load('fz_F_i_recon.dat');
FyrPi = importdata('fz_Phi.txt');
Fzr = load('fy_F_i_recon.dat');
FzrPi = load('fy_Phi_i_recon.dat');
Mxr = load('mx_F_i_recon.dat');
MxrPi = load('mx_Phi_i_recon.dat');
f = load('frequency.dat');
end
Do not include all import commands in [ and ]. [] is Matlab's operator for a concatenation of arrays. With [load('file')] you concatenate the output of load() with nothing, so this is a waste of time only.
Save time by creating constants as constants: 77e9 is cheap, 77*10^9 is an expensive power operation.
There is no reason to create the same variables in a loop repeatedly:
for j=1:4
...
c(1)=60;c(2)=180;c(3)=150;c(4)=100; % Why?! Move it behind the loop
k(1)=1800;k(2)=2400;k(3)=2000;k(4)=2000;
end
  1 commentaire
Steven Lord
Steven Lord le 3 Juin 2022
Do this once only and store the values in a persistent variable:
Alternately load them outside mart.m entirely and pass them into the mart function (which is the ODE function for the system, I assume; I have not looked at all the files) as extra parameters.

Connectez-vous pour commenter.

Plus de réponses (1)

Gloria
Gloria le 3 Juin 2022
Thank you so much! It got much more better !

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by