24小时热门版块排行榜    

查看: 1802  |  回复: 9
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

wtisunday

木虫 (正式写手)

[求助] 非线性方程组matlab拟合

各位大侠,我想搞一下非线性最小二乘拟合,但我的变量x、y分别都是向量,我想用matlab的高斯牛顿法求解,我编的如下:
function ff=fun(vector)
x=vector(1)
y=vector(2)
for i=1:4
    for j=1:4
        A(i,j)=0,B(i,j)=0,b(i)=0,c(i)=0
        for k=1:10
            A(i,j)=A(i,j)+(w(k)*x(j))^2*(w(k)*x(i))^2/(G1(k))^2/(1+(w(k)*...
                x(j))^2)/(1+(w(k)*x(i))^2);
            B(i,j)=B(i,j)+2*y(i)*w(k)^2*x(i)*(w(k)*x(j))^2/(G1(k)^2)/(1+...
                (w(k)*x(i))^2)^2/(1+(w(k)*x(j))^2);
            b(i)=b(i)+(w(k)*x(i))^2/G1(k)/(1+(w(k)*x(i))^2);
            c(i)=c(i)+2*y(i)*x(i)*(w(k))^2/G1(k)/(1+(w(k)*x(i))^2);
        end
    end
end
b=b';
c=c';
ff(1)=A*x-b;
ff(2)=B*y-c;

在赋值x=[1 100 1000 10000],y=[100000,20000,900,20]后出现如下问题:
fsolve(@fun1,x0,y0)

x =

    0.0100


y =

    0.2000


A =

     0


B =

     0


b =

     0


c =

     0

??? Undefined function or method 'w' for input arguments of
type 'double'.

Error in ==> fun1 at 8
            A(i,j)=A(i,j)+(w(k)*x(j))^2*(w(k)*x(i))^2/(G1(k))^2/(1+(w(k)*...
            
Error in ==> fsolve at 254
            fuser = feval(funfcn{3},x,varargin{:});

Caused by:
    Failure in initial user-supplied objective function
    evaluation. FSOLVE cannot continue.

请大家帮帮忙了!万分感谢
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

wtisunday(金币+20): 呵呵,整明白了,主要是fsolve只能解决未知量为向量的 2011-11-24 17:24:29
CODE:
function AA
x=[1 100 1000 10000 100000,20000,900,20];
fsolve(@fun,x)

function ff=fun(x)
w=[0.00100 0.02000 0.1300 0.910000 8.7000 76 1001 4301 20032 100000]';
G1=[1000 2034 3000 4700 6002 10032 50345 109820 620000 1200000]';
G2=[6000 7200 9000 11000 13000 23000 38000 70012 209903 632098]';
for i=5:8
    y(mod(i,5)+1)=x(i);
end
   
for i=1:4
    for j=1:4
        A(i,j)=0,B(i,j)=0,b(i)=0,c(i)=0
        for k=1:10
            A(i,j)=A(i,j)+(w(k)*x(j))^2*(w(k)*x(i))^2/(G1(k))^2/(1+(w(k)*...
                x(j))^2)/(1+(w(k)*x(i))^2);
            B(i,j)=B(i,j)+2*y(i)*w(k)^2*x(i)*(w(k)*x(j))^2/(G1(k)^2)/(1+...
                (w(k)*x(i))^2)^2/(1+(w(k)*x(j))^2);
            b(i)=b(i)+(w(k)*x(i))^2/G1(k)/(1+(w(k)*x(i))^2);
            c(i)=c(i)+2*y(i)*x(i)*(w(k))^2/G1(k)/(1+(w(k)*x(i))^2);
        end
    end
end
b=b';
c=c';
X=x(1:4)';
Y=x(5:8)';
ff1=A*X-b;
ff2=B*Y-c;
ff=[ff1;ff2];

The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
8楼2011-11-24 11:59:12
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 10 个回答

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

w估计是权重,你没有定义,怎么运行呢
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
2楼2011-11-24 11:07:42
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wtisunday

木虫 (正式写手)

还请版主给出详细的解答啊,谢谢了
3楼2011-11-24 11:09:43
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

引用回帖:
3楼: Originally posted by wtisunday at 2011-11-24 11:09:43:
还请版主给出详细的解答啊,谢谢了

能把你的问题详细描述下吗,我好明白你要做什么,要优化的是什么?
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
4楼2011-11-24 11:12:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见