由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Computation版 - 计算中这样的bug!
相关主题
dblquad到底能不能做变积分限的积分啊?a question about Matlab fread
继续我们计算non-prime number 的探险请教一个maple或matlab画图的问题
integration questionStrange compiler error
STrange problem in Fortran programmingft! Strange problem in Matlab!
Re: pls help a list of optimization methods请问a1d=atan(a2d(1,:)./a2d(2,:))中的除数或被除数为零的问题
matlab question: signum and abs问个matlab问题
[转载] 容错性用英语怎么说啊?Textbook for linear algebra?
MPI Write?C++,一个函数完成后出segmentaion fault
相关话题的讨论汇总
话题: cos话题: pi话题: sin话题: dblquad话题: inline
进入Computation版参与讨论
1 (共1页)
g***i
发帖数: 90
1
大家不妨copy下面两行matlab语句到matlab6.0分别执行一下,
看结果是否相同
dblquad('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2)',
-pi/2,pi/2,-pi/2,pi/2)*2*3
dblquad('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2)',
-pi/2,pi/2,-pi/2,pi/2)*2*3
然后看看这两行语句究竟有什么不同?
难道是我的系统有问题?
这么个古怪的bug害惨我了
你也可以试着用函数,呵呵,又有新的bug来了
b*****y
发帖数: 163
2

it seems no problem at all, if you add ellipsis ... at the end of the
first line.

【在 g***i 的大作中提到】
: 大家不妨copy下面两行matlab语句到matlab6.0分别执行一下,
: 看结果是否相同
: dblquad('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2)',
: -pi/2,pi/2,-pi/2,pi/2)*2*3
: dblquad('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2)',
: -pi/2,pi/2,-pi/2,pi/2)*2*3
: 然后看看这两行语句究竟有什么不同?
: 难道是我的系统有问题?
: 这么个古怪的bug害惨我了
: 你也可以试着用函数,呵呵,又有新的bug来了

g***i
发帖数: 90
3
no, of course u write in one line or use ...
here i don't mean syntax error, i mean bug.
try to run the two commands
so it seems strange, right? the two line r the
same, except i use "y" in one line and "p" in another
as the integration variable. but, their results r different

【在 b*****y 的大作中提到】
:
: it seems no problem at all, if you add ellipsis ... at the end of the
: first line.

a*******x
发帖数: 47
4

I have tried your code, the results are different, but still within the error
tolerence of dblquad, which is 1E-6 by default.
If you want identical results, you can either use functions or write as :
dblquad(inline('...', 'x','y/p',), ...)
to specify explicitly the arguments. Otherwise matlab have to decide itself,
which might cause some difference, but still within the error tolerence.

【在 g***i 的大作中提到】
: 大家不妨copy下面两行matlab语句到matlab6.0分别执行一下,
: 看结果是否相同
: dblquad('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2)',
: -pi/2,pi/2,-pi/2,pi/2)*2*3
: dblquad('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2)',
: -pi/2,pi/2,-pi/2,pi/2)*2*3
: 然后看看这两行语句究竟有什么不同?
: 难道是我的系统有问题?
: 这么个古怪的bug害惨我了
: 你也可以试着用函数,呵呵,又有新的bug来了

g***i
发帖数: 90
5
thanks.
no, the error is not in the tolerance. the two results
r so different, one is correct.
and i tried "inline", still the same problem//in fact even
offer the wrong answer of the two

【在 a*******x 的大作中提到】
:
: I have tried your code, the results are different, but still within the error
: tolerence of dblquad, which is 1E-6 by default.
: If you want identical results, you can either use functions or write as :
: dblquad(inline('...', 'x','y/p',), ...)
: to specify explicitly the arguments. Otherwise matlab have to decide itself,
: which might cause some difference, but still within the error tolerence.

a*******x
发帖数: 47
6

Here if I use the inline('..', 'x','y', ...) then the results
are identical.
dblquad(inline('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2)','x','y'), ...
-pi/2,pi/2,-pi/2,pi/2)
dblquad(inline('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2)','x','p'),...
-pi/2,pi/2,-pi/2,pi/2)
results:
ans =
0.08333308868666
ans =
0.08333308868666
Use your codes but without the '**2' at the end,
dblquad('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2

【在 g***i 的大作中提到】
: thanks.
: no, the error is not in the tolerance. the two results
: r so different, one is correct.
: and i tried "inline", still the same problem//in fact even
: offer the wrong answer of the two

g***i
发帖数: 90
7
but unfortunately, that two results are not the
correct one, which is 0.5.

【在 a*******x 的大作中提到】
:
: Here if I use the inline('..', 'x','y', ...) then the results
: are identical.
: dblquad(inline('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2)','x','y'), ...
: -pi/2,pi/2,-pi/2,pi/2)
: dblquad(inline('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2)','x','p'),...
: -pi/2,pi/2,-pi/2,pi/2)
: results:
: ans =
: 0.08333308868666

a*******x
发帖数: 47
8
My code gives an answer of about 1/12, since I had removed the *3*2 at
the end of the inline function, I don't think there is anything wrong.
dblquad(inline('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2) *2*3','x','y'), ...
-pi/2,pi/2,-pi/2,pi/2)
ans =
0.50000008957241
dblquad(inline('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2) *2*3','x','p'), ...
-pi/2,pi/2,-pi/2,pi/2)
ans =
0.50000008957241

【在 g***i 的大作中提到】
: but unfortunately, that two results are not the
: correct one, which is 0.5.

t***h
发帖数: 5601
9
don't know why the second is different, though small.
EDU» format long
EDU» warning off
EDU» dblquad(inline('0.5/pi *cos(x).^3.*cos(y).^4 .*
(sin(x).^2.*cos(y).^2+sin(y).^2)'),-pi/2,pi/2,-pi/2,pi/2)*2*3
ans =
0.50000020278506
EDU» dblquad(inline('0.5/pi *cos(x).^3.*cos(p).^4 .*
(sin(x).^2.*cos(p).^2+sin(p).^2)'),-pi/2,pi/2,-pi/2,pi/2)*2*3
ans =
0.50000057060518
EDU» dblquad(inline('0.5/pi *cos(p).^3.*cos(y).^4 .*
(sin(p).^2.*cos(y).^2+sin(y).^2)'),-pi/2,pi/

【在 a*******x 的大作中提到】
: My code gives an answer of about 1/12, since I had removed the *3*2 at
: the end of the inline function, I don't think there is anything wrong.
: dblquad(inline('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2) *2*3','x','y'), ...
: -pi/2,pi/2,-pi/2,pi/2)
: ans =
: 0.50000008957241
: dblquad(inline('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2) *2*3','x','p'), ...
: -pi/2,pi/2,-pi/2,pi/2)
: ans =
: 0.50000008957241

g***i
发帖数: 90
10
as i mentioned at the begining, this problem only appears
in matlab 6.0
what version do u use?

【在 a*******x 的大作中提到】
: My code gives an answer of about 1/12, since I had removed the *3*2 at
: the end of the inline function, I don't think there is anything wrong.
: dblquad(inline('0.5/pi *cos(x).^3.*cos(y).^4 .* (sin(x).^2.*cos(y).^2+sin(y).^2) *2*3','x','y'), ...
: -pi/2,pi/2,-pi/2,pi/2)
: ans =
: 0.50000008957241
: dblquad(inline('0.5/pi *cos(x).^3.*cos(p).^4 .* (sin(x).^2.*cos(p).^2+sin(p).^2) *2*3','x','p'), ...
: -pi/2,pi/2,-pi/2,pi/2)
: ans =
: 0.50000008957241

a*******x
发帖数: 47
11
6.1. BTW, have you tried my code? what kind of results did you get?
Just out of curiosity.

【在 g***i 的大作中提到】
: as i mentioned at the begining, this problem only appears
: in matlab 6.0
: what version do u use?

g***i
发帖数: 90
12
i guess u must be using 6.1
in 6.1 no problem
test in 6.0, u'll c how strange it is:)

【在 a*******x 的大作中提到】
: 6.1. BTW, have you tried my code? what kind of results did you get?
: Just out of curiosity.

g***i
发帖数: 90
13
in 6.0, even if u use inline. it's still wrong.
and if u use functions, the case is WORSE//wrong for whatever variable

【在 a*******x 的大作中提到】
: 6.1. BTW, have you tried my code? what kind of results did you get?
: Just out of curiosity.

a*******x
发帖数: 47
14
OK, I see. Really strange!

【在 g***i 的大作中提到】
: in 6.0, even if u use inline. it's still wrong.
: and if u use functions, the case is WORSE//wrong for whatever variable

1 (共1页)
进入Computation版参与讨论
相关主题
C++,一个函数完成后出segmentaion faultRe: pls help a list of optimization methods
Matlab作图时如何调整坐标轴范围的其中一个端点的值matlab question: signum and abs
请教一个关于eval的问题[转载] 容错性用英语怎么说啊?
matlab 问题 求教MPI Write?
dblquad到底能不能做变积分限的积分啊?a question about Matlab fread
继续我们计算non-prime number 的探险请教一个maple或matlab画图的问题
integration questionStrange compiler error
STrange problem in Fortran programmingft! Strange problem in Matlab!
相关话题的讨论汇总
话题: cos话题: pi话题: sin话题: dblquad话题: inline