필터 지우기
필터 지우기

ode23, too slow

조회 수: 3 (최근 30일)
Gloria
Gloria 2022년 6월 3일
댓글: Steven Lord 2022년 6월 3일
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
Walter Roberson
Walter Roberson 2022년 6월 3일
https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Walter Roberson
Walter Roberson 2022년 6월 3일
I also suspect that you have a stiff system and should try ode23s

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

채택된 답변

Jan
Jan 2022년 6월 3일
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
Steven Lord
Steven Lord 2022년 6월 3일
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.

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

추가 답변 (1개)

Gloria
Gloria 2022년 6월 3일
Thank you so much! It got much more better !

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by