我尝试使用f2matlab将Fortran代码转换为MATLAB代码,但是它给了我未声明函数或变量“ optimize_wear_rate(dl,zp,kp,zs,ks,pr,tr,sv,dw,ndat,accel ,距离,ap,tc,bt,varargin) 未定义的函数或变量'dl'。”。这就是问题所在。
function [dl, zp, kp, zs, ks, pr, tr, sv, dw, ndat, accel, distance, ap, tc, bt]=optimize_wear_rate(dl, zp, kp, zs, ks, pr, tr, sv, dw, ndat, accel, distance, ap, tc, bt,varargin)
%---------------------------------------------------------------------------------------------------
persistent alpha_ml beta crit_df crit_f crit_rsqr d delalpha df error f g integral iter iter_nr loop maxiter rsqr rsqr_old ;
pr_shape=size(pr);pr=reshape(pr,1,[]);
tr_shape=size(tr);tr=reshape(tr,1,[]);
sv_shape=size(sv);sv=reshape(sv,1,[]);
dw_shape=size(dw);dw=reshape(dw,1,[]);
if isempty(integral), integral=0; end
if isempty(maxiter), maxiter=1000; end
if isempty(crit_rsqr), crit_rsqr=1.0d-08; end
if isempty(crit_df), crit_df=1.0d-20; end
if isempty(crit_f), crit_f=1.0d-20; end
if isempty(d), d=zeros(1,3); end
if isempty(g), g=zeros(1,3); end
if isempty(error), error=0; end
if isempty(beta), beta=0; end
if isempty(rsqr_old), rsqr_old=0; end
if isempty(rsqr), rsqr=0; end
if isempty(alpha_ml), alpha_ml=0; end
if isempty(f), f=0; end
if isempty(df), df=0; end
if isempty(delalpha), delalpha=0; end
if isempty(iter), iter=0; end
if isempty(loop), loop=0; end
if isempty(iter_nr), iter_nr=0; end
ap=7.50d0;
tc=0.50d0;
bt=3.00d0;
d(1:3)=0.0d0;
beta =0.0d0;
rsqr_old=1.0d0;
iter=0;
for loop=1: maxiter
[dl, zp, kp, zs, ks, ap, tc, bt, pr, tr, sv, dw, ndat, accel, distance, error]=error_vs(dl, zp, kp, zs, ks, ap, tc, bt, pr, tr, sv, dw, ndat, accel, distance, error);
%WRITE(*,'(I4, 7(1X,ES12.4))') ITER, SQRT(RSQR_OLD), SQRT(ERROR), AP, TC, BT
[dl, zp, kp, zs, ks, ap, tc, bt, pr, tr, sv, dw, ndat, accel, distance, g]=derror_vs(dl, zp, kp, zs, ks, ap, tc, bt, pr, tr, sv, dw, ndat, accel, distance, g);
rsqr=g(1).^2+g(2).^2+g(3).^2;
beta=0.0d0;
if(loop>1)
beta=rsqr./rsqr_old;
if(sqrt(rsqr./3.0d0)<crit_rsqr)
goto('100');
end
d(1:3)=g(1:3)+beta.*d(1:3);
%---NEWTON_RAPHSON ALGORITHM FOR 1-D SEARCH
alpha_ml=0.0d0;
for iter_nr=1: 1000
[dumvar1,dumvar2,dumvar3, dl, zp, kp, zs, ks, pr, tr, sv, dw, ndat, accel, distance, d, f ]=dalpha_error_vs(ap+alpha_ml.*d(1), tc+alpha_ml.*d(2), bt+alpha_ml.*d(3), dl, zp, kp, zs, ks, pr, tr, sv, dw, ndat, accel, distance, d, f );
[dumvar1,dumvar2,dumvar3, dl, zp, kp, zs, ks, pr, tr, sv, dw, ndat, accel, distance, d, df]=ddalpha_error_vs(ap+alpha_ml.*d(1), tc+alpha_ml.*d(2), bt+alpha_ml.*d(3), dl, zp, kp, zs, ks, pr, tr, sv, dw, ndat, accel, distance, d, df);
if(abs(df)<=crit_df || abs(f)<=crit_f)
tempBreak=1;break;
end
delalpha=-(f./df);
alpha_ml=alpha_ml+delalpha;
end
if ~exist('tempBreak','var'), iter_nr= 1000+1; end; clear tempBreak
ap=ap+alpha_ml.*d(1);
tc=tc+alpha_ml.*d(2);
bt=bt+alpha_ml.*d(3);
rsqr_old=rsqr;
iter=fix(iter+1);
end
% LABEL 100
integral=ap.*((0.5d0.*(5.0d0.^2)-tc.*5.0d0)-(0.5d0.*(tc.^2)-tc.*tc) ).*(0.5d0.*(5.0d0.^2)+bt.*5.0d0);
%---> Final Output is [ gram/sec ]
[writeErrFlag]=writeFmt(1,['%4d',repmat(['%1x','%12.4e'] ,1,8)],'iter','sqrt(rsqr_old)','sqrt(error)','integral','ap','tc','bt');
%---> Changed to m^3/sec multiplied by [ 1E-03/Density ]
return;
end
if ~exist('tempBreak','var'), loop= maxiter+1;
end
clear tempBreak
end