QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2045|回复: 6
打印 上一主题 下一主题

[问题求助] 关于利用matlab非线性拟合的简单问题,求解,毕设急用,在线等

[复制链接]
字体大小: 正常 放大
kuanglei        

2

主题

4

听众

15

积分

升级  10.53%

  • TA的每日心情
    无聊
    2014-6-6 20:36
  • 签到天数: 2 天

    [LV.1]初来乍到

    跳转到指定楼层
    1#
    发表于 2014-5-21 00:42 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
    【培训通知】2013年MCM优秀论文精读培训
    中国数模界最第一大专业科技
    www.madio.net)数学中国
    数学建模思想方法大全精讲专题
    第数学建模思想方法大全精讲专题
    数学建模精品资源课程系列
    国内专业的数学建模实训

    如题,利用lsqcurvefit和lsqnonlin两个函数进行非线性拟合,总是提前收敛,求大神解释为什么?是否是更改里面的options选项,具体怎么改?在线等,万谢。。。
    1、程序代码如下:
    1)编写M-文件 curvefun1.m
    function f=curvefun1(x,tdata)
    f=1-exp(-6.908*(((tdata-x(1))./x(2)).^x(3)));
    %其中 x(1)=cb; x(2)=cb-cc;x(3)=m+1;
    2)输入命令
    tdata=[………];
    ydata=[………];
    x0=[-10,55,2];
    [x,resnorm] =lsqcurvefit('curvefun1',x0,tdata,ydata)
    f= curvefun1(x,tdata);
    3) 结果
    Local minimum possible.
    lsqcurvefit stopped because the finalchange in the sum of squares relative to its initial value is less than the defaultvalue of the function tolerance.
    x =
    Columns 1 through 2
    -3.59020088832205 - 0.62244270778384i 53.9542595923814 + 0.14425192684233i
    Column 3
    2.69114674932468 + 0.0818892331391404i
    resnorm =
    0.00627209364358831
    2、函数介绍如下:
    1)函数 lsqcurvefit
    2)格式 x = lsqcurvefit(fun,x0,xdata,ydata)
    x =lsqcurvefit(fun,x0,xdata,ydata,lb,ub)
    x =lsqcurvefit(fun,x0,xdata,ydata,lb,ub,options)
    [x,resnorm] = lsqcurvefit(…)
    [x,resnorm,residual] = lsqcurvefit(…)
    [x,resnorm,residual,exitflag] =lsqcurvefit(…)
    [x,resnorm,residual,exitflag,output]= lsqcurvefit(…)
    [x,resnorm,residual,exitflag,output,lambda]= lsqcurvefit(…)
    [x,resnorm,residual,exitflag,output,lambda,jacobian]=lsqcurvefit(…)
    3)参数说明:
    x0为初始解向量;xdata,ydata为满足关系ydata=F(x, xdata)的数据;
    lb、ub为解向量的下界和上界,若没有指定界,则lb=[ ],ub=[ ];
    options为指定的优化参数;
    fun为拟合函数,其定义方式为:x = lsqcurvefit(@myfun,x0,xdata,ydata),
    其中myfun已定义为 function F = myfun(x,xdata)
    F = … % 计算x处拟合函数值fun的用法与前面相同;
    resnorm=sum ((fun(x,xdata)-ydata).^2),即在x处残差的平方和;
    residual=fun(x,xdata)-ydata,即在x处的残差;
    exitflag为终止迭代的条件;
    output为输出的优化信息;
    lambda为解x处的Lagrange乘子;
    jacobian为解x处拟合函数fun的jacobian矩阵。
    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信

    90

    主题

    105

    听众

    9483

    积分

  • TA的每日心情

    2017-1-30 23:35
  • 签到天数: 318 天

    [LV.8]以坛为家I

    2010挑战赛参赛者

    2011挑战赛参赛者

    2012挑战赛参赛者

    2013挑战赛参赛者

    社区QQ达人

    群组物联网工程师培训

    群组Matlab讨论组

    群组2013认证赛C题讨论群组

    群组数学建模

    群组2013认证赛A题讨论群组


    lsqnonlin函数用来求平方和形式的函数的最小值,lsqcurvefit函数用来求解目标函数的最小二乘解,其目标函数就是做数据拟合时构造的平方和形式的目标函数,lsqcurvefit函数和lsqnonlin函数采用相同的算法,只是lsqcurvefit函数可以直接做数据拟合,而用lsqnonlin函数做数据拟合的话还需要自己构造目标函数 .
    多多发帖,受益多多
    回复

    使用道具 举报

    90

    主题

    105

    听众

    9483

    积分

  • TA的每日心情

    2017-1-30 23:35
  • 签到天数: 318 天

    [LV.8]以坛为家I

    2010挑战赛参赛者

    2011挑战赛参赛者

    2012挑战赛参赛者

    2013挑战赛参赛者

    社区QQ达人

    群组物联网工程师培训

    群组Matlab讨论组

    群组2013认证赛C题讨论群组

    群组数学建模

    群组2013认证赛A题讨论群组

      Examples
          FUN can be specified using @:
             xdata = [5;4;6];          % example xdata
             ydata = 3*sin([5;4;6])+6; % example ydata
             x = lsqcurvefit(@myfun, [2 7], xdata, ydata)

        where myfun is a MATLAB function such as:

            function F = myfun(x,xdata)
            F = x(1)*sin(xdata)+x(2);

        FUN can also be an anonymous function:
            x = lsqcurvefit(@(x,xdata) x(1)*sin(xdata)+x(2),[2 7],xdata,ydata)

        If FUN is parameterized, you can use anonymous functions to capture the
        problem-dependent parameters. Suppose you want to solve the
        curve-fitting problem given in the function myfun, which is
        parameterized by its second argument c. Here myfun is a MATLAB file
        function such as

            function F = myfun(x,xdata,c)
            F = x(1)*exp(c*xdata)+x(2);

        To solve the curve-fitting problem for a specific value of c, first
        assign the value to c. Then create a two-argument anonymous function
        that captures that value of c and calls myfun with three arguments.
        Finally, pass this anonymous function to lsqcurvefit:

            xdata = [3; 1; 4];           % example xdata
            ydata = 6*exp(-1.5*xdata)+3; % example ydata     
            c = -1.5;                    % define parameter
            x = lsqcurvefit(@(x,xdata) myfun(x,xdata,c),[5;1],xdata,ydata)
    多多发帖,受益多多
    回复

    使用道具 举报

    90

    主题

    105

    听众

    9483

    积分

  • TA的每日心情

    2017-1-30 23:35
  • 签到天数: 318 天

    [LV.8]以坛为家I

    2010挑战赛参赛者

    2011挑战赛参赛者

    2012挑战赛参赛者

    2013挑战赛参赛者

    社区QQ达人

    群组物联网工程师培训

    群组Matlab讨论组

    群组2013认证赛C题讨论群组

    群组数学建模

    群组2013认证赛A题讨论群组

    Examples
          FUN can be specified using @:
             x = lsqnonlin(@myfun,[2 3 4])

        where myfun is a MATLAB function such as:

            function F = myfun(x)
            F = sin(x);

        FUN can also be an anonymous function:

            x = lsqnonlin(@(x) sin(3*x),[1 4])

        If FUN is parameterized, you can use anonymous functions to capture the
        problem-dependent parameters. Suppose you want to solve the non-linear
        least squares problem given in the function myfun, which is
        parameterized by its second argument c. Here myfun is a MATLAB file
        function such as

            function F = myfun(x,c)
            F = [ 2*x(1) - exp(c*x(1))
                  -x(1) - exp(c*x(2))
                  x(1) - x(2) ];

        To solve the least squares problem for a specific value of c, first
        assign the value to c. Then create a one-argument anonymous function
        that captures that value of c and calls myfun with two arguments.
        Finally, pass this anonymous function to lsqnonlin:

            c = -1; % define parameter first
            x = lsqnonlin(@(x) myfun(x,c),[1;1])

    点评

    kuanglei  您说的我知道,函数形式,数据点我都有,程序代码也没错,只是它提前收敛了,没有运行出最优解(我的是实际问题,它的结果居然是复数),我想知道怎么调才能让它运行出正确结果。函数调用有个options选项,我不会用,不  详情 回复 发表于 2014-5-21 17:24
    多多发帖,受益多多
    回复

    使用道具 举报

    kuanglei        

    2

    主题

    4

    听众

    15

    积分

    升级  10.53%

  • TA的每日心情
    无聊
    2014-6-6 20:36
  • 签到天数: 2 天

    [LV.1]初来乍到

    平凡之不凡 发表于 2014-5-21 14:24
    Examples
          FUN can be specified using @:
             x = lsqnonlin(@myfun,[2 3 4])

    您说的我知道,函数形式,数据点我都有,程序代码也没错,只是它提前收敛了,没有运行出最优解(我的是实际问题,它的结果居然是复数),我想知道怎么调才能让它运行出正确结果。函数调用有个options选项,我不会用,不知道是不是可以在里面调。
    我是新手,没怎么逛过数学中国的论坛,只因为之前参加过数模比赛,接触过matlab并且知道数模大神多,才来这里发帖求助。
    另外,我的英语很龊,能加QQ单独质询吗?我的QQ894407008,万谢。。。。
    回复

    使用道具 举报

    kuanglei        

    2

    主题

    4

    听众

    15

    积分

    升级  10.53%

  • TA的每日心情
    无聊
    2014-6-6 20:36
  • 签到天数: 2 天

    [LV.1]初来乍到

    回复

    使用道具 举报

    21

    主题

    97

    听众

    3110

    积分

  • TA的每日心情
    奋斗
    2014-3-2 00:26
  • 签到天数: 243 天

    [LV.8]以坛为家I

       看你的拟合方程式非线性程度很高啊!如果实在要得到答案的话尝试下1stOpt吧!
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册地址

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2025-8-3 04:37 , Processed in 1.767931 second(s), 89 queries .

    回顶部