A voir également:
- Optimisation d'un programme matlab
- Optimisation pc - Accueil - Utilitaires
- Programme demarrage windows 10 - Guide
- Mettre en veille un programme - Guide
- Optimisation découpe panneau gratuit - Télécharger - Outils professionnels
- Cette action ne peut pas être réalisée car le fichier est ouvert dans un autre programme - Guide
2 réponses
s'il vous plais jai besoin d'un coup de main, le programme suivant prend des heurs pour donner le résultat. je suis pas un pro de programmation, je matipule des grosses matrice, j'aimerai l'optimiser y a t'il un moyen est comment.
merci beaucoup.
programme:
function S=sample(M,p)
% This function samples two dimentional matrices in the row sens
% Syntax: S=sample(M,p)
% Where M is the matrix to sample and p is the step (>=1)
% and S the sampled matrix
% To make the function work in the column sens simply transpose M, and
% finaly transpose the result S
[m,n]=size(M);
% Verifies the step value
if p==m
S(1,:)=M(1,:);
return
elseif (p>m | p<1)
error('The step p must be < the number of rows')
return
end
% Computes the sampled matrix
S(1,:)=M(1,:);
for i=p:p:m
S(1+i/p,:)=M(i+1,:);
end
merci beaucoup.
programme:
function S=sample(M,p)
% This function samples two dimentional matrices in the row sens
% Syntax: S=sample(M,p)
% Where M is the matrix to sample and p is the step (>=1)
% and S the sampled matrix
% To make the function work in the column sens simply transpose M, and
% finaly transpose the result S
[m,n]=size(M);
% Verifies the step value
if p==m
S(1,:)=M(1,:);
return
elseif (p>m | p<1)
error('The step p must be < the number of rows')
return
end
% Computes the sampled matrix
S(1,:)=M(1,:);
for i=p:p:m
S(1+i/p,:)=M(i+1,:);
end
tion [fx,gr,ind2] = calcf(x,ind)
fx=0.0;
Cc=10000/3600;
Ch=10000/3600;
Si=100;
Tsci=273;
Tshi=293;
Tsc0=263;
gr=0.0*x;
r=1D-4;
ind2=1;
if ind==2 | ind==4
deff('y=h1(x)','y=x(4)+x(3)-2');
deff('y=h2(x)','y=x(4)*Cc*(Tsci*x(1)/x(2)-Tsci-x(1)+x(2))+x(3)*Ch*(Tshi-x(1))+x(4)*Cc(Tshi-x(2))');
deff('y=h3(x)','y=x(3)*Ch*(Tshi/x(1)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