数学建模社区-数学中国

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

作者: legan    时间: 2009-8-26 15:40
标题: 一个非线性曲线拟合问题的请教
我们的问题是想用非线性最小二乘拟合出人口增长模型中Logistic的函数0 q8 p* _7 G0 }  y' X& X4 _& u
xt=xm/(1+(xm/x0-1)*exp(-rt))求出环境允许的最大值xm和增长率r& W. l0 d+ P6 V4 ]$ v
我们用的matlab中的lsqcurvefitlsqnonlin函数出现了问题,我们的函数如下:9 K/ X! M( B( g- c
一、用lsqcurvefit函数求解' F, N/ e; g: [( ?  a" Y( I/ E% {
%定义flogistic1函数并保存
* }: h' C( ~3 e' g. q# w* `
function f=flogistic1(x,tdata)
f=x(1)/(1+(x(1)/243-1)*exp(-x(2)*t));
%主程序+ d" ]$ K. X* m1 R' [% t
tdata=2000:2009;
ydata=[2434 c+ X8 S. Y$ B, j6 m" @- ~
289 324 372 393 417 435 549 10865 q2 U7 b1 ]$ M/ ]/ T
1263];
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函数并保存6 E  V9 `, m4 Q4 \
function f=flogistic2(x)
tdata=2000:1:2009;
ydata=[2432 b5 v: C5 }$ m4 J( c
289 324 372 393 417 435 549 1086 1263];
f=ydata-x(1)/(1+(x(1)/243-1)*exp(-x(2)*tdata))
%主程序
. M4 G6 `1 j5 `2 {) g7 L0 ]4 U& Q
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方法直接模拟试试
- Y3 z% r( F# Q9 k5 N非线性回归分析
" i1 w; ~, j1 M4 i9 m% Y& O6 d前提是把数据整理好
! x  F# o# G' f+ q; B. a( z[beta,r,j]=nlinfit(x,y,'function')+ I  b* Q- G: W
nlintool(x,y,'function',置信区间)
作者: handsome8848    时间: 2009-8-30 19:33
拟合?求最大值?LZ到底要表达什么意思。。。
8 Q* d% ^, t/ y拟合还能求最大值?
作者: 杨帆    时间: 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