필터 지우기
필터 지우기

What function should I use to speed up code instead of GLOBAL

조회 수: 2 (최근 30일)
Babak
Babak 2015년 2월 24일
답변: John D'Errico 2015년 2월 24일
Hello,
Here is my problem. I have a ODE45 solver which use part of 5 big precalculated matrixes (fixed matrxices which will not be updated) to simulate my program. When I run the program it is very time consuming and I am looking for a way to speed up this process. I know that using global value is not a good idea. what can I used instead of global to speed up the process?? My code is like this:
clc
clear all
Load A B C D F
global A B C D F
[tout,y]=ode45('sys',(0:1/3600:0.5),zeros(50,1));
% ___________________________________
%%Inside the function (sys) %%
function xdot = sys(t,x)
global A B C D F
...

답변 (1개)

John D'Errico
John D'Errico 2015년 2월 24일
Um, while I dislike the use of global variables anywhere as they are essentially never needed, They are surely not the problem here, but a function handle can help you to pass in those variables trivially into your function sys. It won't change the speed by much at all though.
What is the problem is anyone's guess, since we have not a clue as to what is inside sys. You may have a stiff system, so use of a tool that is designed to work with stiff systems may help. Or it may be nothing more that you are impatient, and don't want to wait for the ODE solver to solve a problem with 50 variables. Bigger problems take more time.
I might suggest learning how to use the profiling tool, as it can often help you to speed up your code.
Sorry, but there is rarely a magic salve you can apply to a problem to make things run faster. Ok, a faster computer helps.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by