数学建模社区-数学中国
标题: 一个非线性曲线拟合问题的请教 [打印本页]
作者: legan 时间: 2009-8-26 15:40
标题: 一个非线性曲线拟合问题的请教
我们的问题是想用非线性最小二乘拟合出人口增长模型中Logistic的函数
8 S$ A! w8 n+ Y' Px(t)=xm/(1+(xm/x0-1)*exp(-rt))求出环境允许的最大值xm和增长率r;. E* @, y4 A* W1 G1 P7 ^. w2 O+ B
我们用的matlab中的lsqcurvefit和lsqnonlin函数出现了问题,我们的函数如下:$ B0 v4 C- k1 p4 a1 H
一、用lsqcurvefit函数求解! Q i g0 R9 L; D
%定义flogistic1函数并保存4 S% p% ~: l. d( s3 ?( `; s* ]/ O
function f=flogistic1(x,tdata)
f=x(1)/(1+(x(1)/243-1)*exp(-x(2)*t));
%主程序
s& A8 ^" I; w$ ?9 b; Jydata=[243! _5 W( F7 v2 }; h3 ~
289 324 372 393 417 435 549 1086
2 m1 g; N) c0 N* p7 ^ z( ]1263];
x=lsqcurvefit('flogistic1',x0,tdata,ydata)
??? Error using ==> optim\private\lsqncommon
User supplied function ==> flogistic1
failed with the following error:
Matrix dimensions must agree.
Error in ==> lsqcurvefit at 165
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
%定义flogistic2函数并保存7 ]/ n, A6 c4 ?5 I2 c8 [
ydata=[243- Q7 t9 e# Q5 h9 L: S. S
289 324 372 393 417 435 549 1086 1263];
f=ydata-x(1)/(1+(x(1)/243-1)*exp(-x(2)*tdata))
%主程序
& V- l3 @8 u$ Hx=lsqnonlin('flogistic2',x0)
??? Error using ==> optim\private\lsqncommon
User supplied function ==> flogistic2
failed with the following error:
Matrix dimensions must agree.
Error in ==> lsqnonlin at 163
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
作者: legan 时间: 2009-8-26 15:40
希望好心人能帮我们解决下,感激不尽
作者: 东方明珠-WDZYQ 时间: 2009-8-26 16:46
查看MATLAB的help啊
作者: jd_lim 时间: 2009-8-29 00:13
可以用nlinfit方法直接模拟试试
, `8 {* a4 P: a1 w: @非线性回归分析# P O7 C& a/ Y8 e& d6 e$ f
前提是把数据整理好9 u$ o. j4 m/ I
[beta,r,j]=nlinfit(x,y,'function')
1 L9 q* C- X+ _nlintool(x,y,'function',置信区间)
作者: handsome8848 时间: 2009-8-30 19:33
拟合?求最大值?LZ到底要表达什么意思。。。
1 y7 P+ k' l6 ^/ Z- R" g) L! s/ x拟合还能求最大值?
作者: 杨帆 时间: 2009-8-30 20:04
谢谢楼主分享 。。。。
作者: 杨帆 时间: 2009-8-30 20:16
谢谢楼主分享 。。。。
作者: xieedemzitou 时间: 2009-9-3 12:52
4L有道理。。
作者: alair009 时间: 2012-1-26 11:32
恩,参考一下。。88450640562953597917111575064111625743336822603965473801748718741200358398380672
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) |
Powered by Discuz! X2.5 |