数学建模社区-数学中国

标题: 一个非线性曲线拟合问题的请教 [打印本页]

作者: legan    时间: 2009-8-26 15:40
标题: 一个非线性曲线拟合问题的请教
我们的问题是想用非线性最小二乘拟合出人口增长模型中Logistic的函数
9 Q4 o1 Q+ p: `$ t* u1 Jxt=xm/(1+(xm/x0-1)*exp(-rt))求出环境允许的最大值xm和增长率r9 R+ \( a; j' m! Q2 O
我们用的matlab中的lsqcurvefitlsqnonlin函数出现了问题,我们的函数如下:( m3 M7 W8 B8 [8 k  Q- \/ g
一、用lsqcurvefit函数求解) X3 P/ N, m0 o& `, i0 U
%定义flogistic1函数并保存
9 n2 k* e7 E2 F- k: g' S
function f=flogistic1(x,tdata)
f=x(1)/(1+(x(1)/243-1)*exp(-x(2)*t));
%主程序
0 ~* S8 {* }3 N- g3 o
tdata=2000:2009;
ydata=[243
* D$ C* R$ j3 n/ B- j- q289 324 372 393 417 435 549 1086
# R$ \( ^  r3 I6 [- u: U5 C1263];
x0=[2000 0.5];
x=lsqcurvefit('flogistic1',x0,tdata,ydata)
f=flogistic1(x,tdata)
执行后出现的问题是:
??? Error using ==> optim\private\lsqncommon
User supplied function ==> flogistic1
failed with the following error:
Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> lsqcurvefit at 165
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
二、用lsqnonlin函数求解
%定义flogistic2函数并保存
( g  R4 h  c; W2 x% r
function f=flogistic2(x)
tdata=2000:1:2009;
ydata=[243$ @6 l7 t7 B! J( x- N& _/ q- }
289 324 372 393 417 435 549 1086 1263];
f=ydata-x(1)/(1+(x(1)/243-1)*exp(-x(2)*tdata))
%主程序
2 v: V7 Z. r$ \: J6 z
x0=[2000 0.5];
x=lsqnonlin('flogistic2',x0)
f=fogistic2(x)
执行后出现的问题是
??? Error using ==> optim\private\lsqncommon
User supplied function ==> flogistic2
failed with the following error:
Error using ==> mrdivide
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方法直接模拟试试
/ Y# u3 ?% ?: z2 k* `0 V" M8 Z非线性回归分析7 a& f" a! n1 q) |% R0 e
前提是把数据整理好- M6 z+ I0 n9 s1 e- s, |. T, D. a
[beta,r,j]=nlinfit(x,y,'function')
+ v) ~) ~$ U5 t  Ynlintool(x,y,'function',置信区间)
作者: handsome8848    时间: 2009-8-30 19:33
拟合?求最大值?LZ到底要表达什么意思。。。
0 Y2 v4 w+ f4 `- N3 P拟合还能求最大值?
作者: 杨帆    时间: 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