声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1308|回复: 8

[编程技巧] 哪位高手给我看看问题出在什么地方了

[复制链接]
发表于 2010-2-2 13:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
function f = funzh1(a);
f1 =int(x*exp(a(1)*x),x,-3,3)/m(1)*int(exp(a(1)*x),x,-3,3);
f2 =int(x^2*exp(a(2)*x^2),x,-3,3)/m(2)*int(exp(a(2)*x^2),x,-3,3)
f3 =int(x^3*exp(a(3)*x^3),x,-3,3)/m(3)*int(exp(a(3)*x^3),x,-3,3);
f = f1.^2+f2.^2+f3.^2
%%%%%%%%%%%%%%%%%%%%%%%%%
>> m =[-0.0395 0.8244 -0.0655];
>> a0 =[-1 0 0];
>> a =lsqnonlin(funzh1,a0)
??? Input argument "x" is undefined.
Error in ==> funzh1 at 2
f1 =int(x*exp(a(1)*x),x,-3,3)/m(1)*int(exp(a(1)*x),x,-3,3);
>> a =lsqnonlin(funzh1,a0)
??? Undefined function or variable 'x'.
Error in ==> funzh1 at 2
f1 =int(x*exp(a(1)*x),x,-3,3)/m(1)*int(exp(a(1)*x),x,-3,3);
回复
分享到:

使用道具 举报

 楼主| 发表于 2010-2-2 14:42 | 显示全部楼层

请高手指教,是在不知道错在什么地方了

function f =zhfun(a)
f1 = int(x*exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(1)*int(exp(a(1)*x+a(2)*x^2 +a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
f2 =int(x^2*exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(2)*int(exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
f3 =int(x^3*exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(3)*int(exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
f4 = int(x^4*exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(4)*int(exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
f5 =int(x^5*exp(a(1)*x+a(2)*x^2 +a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(5)*int(exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
f =f1.^2+f2.^2+f3.^2+f4.^2+f5.^2

%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> m =[-0.0395,0.8244,-0.0655,1.61858,-0.1283];
>> a0 =[-1,0,0,0,0];
>> a=lsqnonlin(zhfun,a0)
??? Input argument "x" is undefined.
Error in ==> zhfun at 2
f1 = int(x*exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(1)*int(exp(a(1)*x+a(2)*x^2 +a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
>> a =lsqnonlin(zhfun,a0)
??? Undefined function or variable 'x'.
Error in ==> zhfun at 2
f1 = int(x*exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(1)*int(exp(a(1)*x+a(2)*x^2 +a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
>> syms x
>> a =lsqnonlin(zhfun,a0)
??? Undefined function or variable 'x'.
Error in ==> zhfun at 2
f1 = int(x*exp(a(1)*x+a(2)*x^2+a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3)/m(1)*int(exp(a(1)*x+a(2)*x^2 +a(3)*x^3+a(4)*x^4+a(5)*x^5),x,-3,3);
>>
发表于 2010-2-2 15:42 | 显示全部楼层
不是跟你说"x" is undefined了?
函数中x,m是什么东西, 都没定义阿!

还有基本上两帖有点类似!? 是否使用编辑即可!
 楼主| 发表于 2010-2-27 13:11 | 显示全部楼层

matlab中的高斯牛顿法,怎么用?

我有一个非线性方程组,用fsolve求解时总是显示错误,好像是说要用高斯牛顿法求解,可是我不知道怎么用的,由于本人不懂英语,所以看帮助根本看不了,请高人指点,程序错误时这么写的:Warning: Default trust-region dogleg method of FSOLVE cannot
handle non-square systems; switching to Gauss-Newton method.
> In fsolve at 232
Conditioning of Gradient Poor - Switching To LM method
Optimization terminated: directional derivative along
search direction less than TolFun and infinity-norm of
gradient less than 10*(TolFun+TolX).
 楼主| 发表于 2010-2-27 19:57 | 显示全部楼层

matlab积分问题

“x*exp(ax+bx2+cx3)在特定区间内的积分怎么求啊,应该用哪个函数,我试过fsolve /cumtrapz/trapz都出错,怎么办啊,其中x2表示x 的平方,x3为立方请高手指点下
发表于 2010-3-1 13:10 | 显示全部楼层
原帖由 2008057 于 2010-2-27 19:57 发表
“x*exp(ax+bx2+cx3)在特定区间内的积分怎么求啊,应该用哪个函数,我试过fsolve /cumtrapz/trapz都出错,怎么办啊,其中x2表示x 的平方,x3为立方请高手指点下


int(x*exp(a*x+b*x^2+c*x^3),0,100)
%[0 100]内积分
 楼主| 发表于 2010-3-1 14:56 | 显示全部楼层

谢谢,可是还有错误

谢谢回复,这个试过了,总是显示如下错误,不知道什么原因
>> syms a b c x
>> int(x*exp(a*x+b*x^2+c*x^3),-0.1,0.1)
Warning: Explicit integral could not be found.
> In sym.int at 58

ans =

int(x*exp(a*x+b*x^2+c*x^3),x = -1/10 .. 1/10)
发表于 2010-3-1 21:27 | 显示全部楼层
找一本matlab数学实验相关的书籍,上面应该有详细的介绍:@)
 楼主| 发表于 2010-3-2 11:32 | 显示全部楼层

回复 板凳 ChaChing 的帖子

这个不只是x未定义的问题,定义之后还是有错误,下一个错误提示能帮我分析下吗,好像是M文件的第二行有错,是不是表达式不对呀,还是用的函数有错误
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-14 16:24 , Processed in 0.076417 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表