24小时热门版块排行榜    

查看: 1863  |  回复: 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

荣誉版主 (著名写手)

【答案】应助回帖

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的回帖

wtisunday

木虫 (正式写手)

我是要优化求解x,y的值,也就是两组向量值,式子中的w、G1、G2都是实验测量量,为已知。程序中的i和j就是我想求的向量中的元素个数。不知道这么说可以吗
5楼2011-11-24 11:16:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

麻烦你给出w G1 G2的数值,要不然我只随便取些做个范例帮你算一下了
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.
6楼2011-11-24 11:24:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wtisunday

木虫 (正式写手)

w:
0.00100000000000000
0.0200000000000000
0.130000000000000
0.910000000000000
8.70000000000000
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
7楼2011-11-24 11:29:43
已阅   回复此楼   关注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的回帖

wtisunday

木虫 (正式写手)

你给的程序还是无法运行啊
9楼2011-11-24 14:36:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

直接复制代码 到editor中保存为m文件,然后点run

结果是


No solution found.

fsolve stopped because the relative size of the current step is less than the
default value of the step size tolerance squared, but the vector of function values
is not near zero as measured by the default value of the function tolerance.




ans =

  1.0e+004 *

    0.0000    0.0100    0.1000    1.0000   10.0000    2.0000    0.0900    0.0020

你的初值不太合适
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.
10楼2011-11-24 16:31:11
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 wtisunday 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 085601求调剂 +3 Du.11 2026-03-16 3/150 2026-03-16 20:42 by 无际的草原
[考研] 机械专硕325,寻找调剂院校 +3 y9999 2026-03-15 5/250 2026-03-16 19:58 by y9999
[考研] 0854控制工程 359求调剂 可跨专业 +3 626776879 2026-03-14 9/450 2026-03-16 17:42 by 626776879
[考研] 梁成伟老师课题组欢迎你的加入 +8 一鸭鸭哟 2026-03-14 9/450 2026-03-16 17:35 by 沐霖12138
[考研] 一志愿苏州大学材料工程(085601)专硕有科研经历三项国奖两个实用型专利一项省级立项 +3 大火山小火山 2026-03-16 5/250 2026-03-16 16:54 by barlinike
[考研] 321求调剂 +5 大米饭! 2026-03-15 5/250 2026-03-16 16:33 by houyaoxu
[考研] 285求调剂 +6 ytter 2026-03-12 6/300 2026-03-16 15:05 by njzyff
[考研] 309求调剂 +5 花与叶@ 2026-03-10 5/250 2026-03-16 14:13 by 哦哦123
[考研] 344求调剂 +3 knight344 2026-03-16 3/150 2026-03-16 09:42 by 无际的草原
[考研] 274求调剂 +4 时间点 2026-03-13 4/200 2026-03-15 15:29 by Rambo13
[考研] 265求调剂 +4 威化饼07 2026-03-12 4/200 2026-03-14 17:23 by userper
[考研] 材料与化工(0856)304求B区调剂 +7 邱gl 2026-03-10 11/550 2026-03-14 12:18 by 邱gl
[考研] 336求调剂 +6 Iuruoh 2026-03-11 6/300 2026-03-13 22:06 by JourneyLucky
[考研] 311求调剂 +3 冬十三 2026-03-13 3/150 2026-03-13 20:41 by JourneyLucky
[考研] 301求调剂 +6 Liyouyumairs 2026-03-11 6/300 2026-03-13 20:11 by JourneyLucky
[考研] 293求调剂 +3 世界首富 2026-03-11 3/150 2026-03-13 16:27 by JourneyLucky
[考研] 290求调剂 +7 ADT 2026-03-12 7/350 2026-03-13 15:17 by JourneyLucky
[考研] 268求调剂 +4 好运连绵不绝 2026-03-12 4/200 2026-03-13 10:45 by hyswxzs
[考研] 08食品或轻工求调剂,本科发表3篇sci一区top论文,一志愿南师大食品科学与工程 +3 我是一个兵, 2026-03-10 3/150 2026-03-13 10:21 by Yuyi.
[考研] 一志愿河海大学085900土木水利专硕279求调剂不挑专业 +4 SunWwWwWw 2026-03-10 8/400 2026-03-13 02:23 by SunWwWwWw
信息提示
请填处理意见