过路的大神帮帮忙
dat=importdata('data.txt');
n=length(dat);
x=dat(:,2);
y=dat(:,4);
y1=dat(:,5);
a0=[0 0 0 0];
a=lsqcurvefit('cepian',a0,x,y)这是主程序
函数程序为
function y=cepian(a,x)
Fz=2000;
uy=a(1)+a(2)*Fz+a(3)*Fz^2;
E1=0.5/(1+exp(-(Fz-a(1))/a(2)));
qy=a(4)*tan(x)/(uy*Fz);
z=-abs(qy)-E1*(abs(qy.^2))-(E1^2+1/12)*(abs(qy.^3));
Fy=1-exp(z);
y=(-qy/(abs(qy)))*uy*Fz*Fy;
总是出错如下
dat=importdata('data.txt');
n=length(dat);
x=dat(:,2);
y=dat(:,4);
y1=dat(:,5);
a0=[0 0 0 0];
a=lsqcurvefit('cepian',a0,x,y)
Warning: Rank deficient, rank = 0, tol = NaN.
> In cepian at 8
In lsqcurvefit at 209
??? Error using ==> snls at 46
Objective function is returning undefined values at initial point.lsqcurvefit cannot continue.
Error in ==> lsqncommon at 149
[xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]=...
Error in ==> lsqcurvefit at 258
[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
求神助啊

 Réponse acceptée

koneb
koneb le 21 Nov 2022

0 votes

把你的初值带入函数,得到Nan才引起了这个问题,只要修改一下a0的初始值,使函数中分母不为0即可,修改后程序如下:
%% 清空环境变量
close all; clear; clc;
%% 主程序
dat=importdata('data.txt');
n=length(dat);
x=dat(:,2);
y=dat(:,4);
y1=dat(:,5);
a0=[0 0 0 1];
a=lsqcurvefit('cepian',a0,x,y)

Plus de réponses (0)

Catégories

En savoir plus sur 优化 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!