回 帖 发 新 帖 刷新版面

主题:帮忙看下我的这个程序哪里出错了,应该怎么改?

function wilson 
clear all;clc 
x1=[0.147049039,0.131086539,0.157613152,0.180129431,0.207201277,0.22746969,0.255415251,0.099481423,0.117878776,0.137541922,0.154620434,0.177639128,0.191054291,0.214879884,0.077743014,0.092163476,0.103572331,0.116350176,0.129210867,0.140870207,0.155272458,0.068726596,0.078135143,0.091191526,0.101048452,0.109127287,0.119329425,0.131480142]'; 
x2=[0.852950961,0.868913461,0.842386848,0.819870569,0.792798723,0.77253031,0.744584749,0.766017544,0.750368011,0.733641742,0.719114069,0.699533437,0.688121956,0.667854943,0.580501157,0.571424409,0.564243272,0.556200445,0.548105471,0.54076667,0.531701384,0.507774972,0.502644981,0.495526014,0.490151545,0.485746576,0.48018388,0.473558726]'; 
x3=[0,0,0,0,0,0,0,0.134501034,0.131753214,0.128816335,0.126265497,0.122827435,0.120823753,0.117265173,0.341755828,0.336412115,0.332184397,0.327449379,0.322683662,0.318363123,0.313026158,0.423498432,0.419219876,0.41328246,0.408800004,0.405126137,0.400486695,0.394961132]'; 
y=[1.916941284,2.031857439,1.847578254,1.714052235,1.574042537,1.480721213,1.36485203,2.307736492,2.138058372,1.983793119,1.866754586,1.727979087,1.655180579,1.537663491,2.554298714,2.38415123,2.267451659,2.151123488,2.046287511,1.959899261,1.862561318,2.677571155,2.549275221,2.394759903,2.292127768,2.215218238,2.125850267,2.028886858]'; 
x=[x1,x2,x3]; 
beta0=[1,1,1,1,1,1]; 
a=nlinfit(x,y,@myfun,beta0) 
function yhat=myfun(a,x) 
yhat=1-log(x(:,1)+x(:,2)*exp(a(1))+x(:,3)*exp(a(2)))... 
-x(:,1)./(x(:,1)+x(:,2)*exp(a(1))+x(:,3)*exp(a(2)))... 
-(x(:,2)*exp(a(3)))./(x(:,1)*exp(a(3))+x(:,2)+x(:,3)*exp(a(4)))... 
-(x(:,3)*exp(a(5)))./(x(:,1)*exp(a(5))+x(:,2)*exp(a(6))+x(:,3));

运行后显示:
??? Error using ==> nlinfit>checkFunVals
MODELFUN has returned Inf or NaN values.

Error in ==> nlinfit at 201
    if funValCheck && ~isfinite(sse), checkFunVals(r); end

Error in ==> wilson at 9
a=nlinfit(x,y,@myfun,beta0) 

回复列表 (共1个回复)

沙发

我已经发现是我的初值有问题了,请问初值应该取多少,有什么好的取初值的办法吗?

我来回复

您尚未登录,请登录后再回复。点此登录或注册