Cannot compute number of steps
이전 댓글 표시
Hey,
Im trying to integrate using the trapezoid method, and works just fine when working with constant boundaries. However i'm having a hard time coming around this issue:
Error using : (line 38)
Cannot compute the number of steps from 0 to 5*sin((xx*pi)/10) by (5*sin((xx*pi)/10))/round(50*sin((xx*pi)/10)).
Error in Lab2 (line 24)
y=[0:hy:ymax(xx)] ;
n=100;
hx=10/n;
x=[0:hx:10];
ymax= @ (xx)5.*sin(pi.*xx./10);
syms xx
hy=ymax(xx)/round(ymax(xx)/hx);
y=[0:hy:ymax(xx)] ;
[xx,yy]=ndgrid(x,y);
mat = exp(-0.25.*((xx-8).^2 + (yy-0).^2)) .*cos((xx-8-yy)/6); %trapets
b{1}=x; b{2}=y;
T=trapets(b,mat,2);
F = @(x,y)exp(-0.25.*((x-8).^2 + (y-0).^2)).*cos((x-8-y)/6); %integral
Refvalue=integral2(F,0,10,0,ymax) ;
disp(T)
What to do?
댓글 수: 3
John D'Errico
2016년 2월 26일
So, you found some function that we don't have and cannot see, called trapets. Now you have a problem with it. How can we know what is the problem?
Contact the source of the code. Ask them.
Philip Baczek
2016년 2월 26일
Philip Baczek
2016년 2월 26일
편집: Walter Roberson
2016년 2월 26일
답변 (1개)
Walter Roberson
2016년 2월 26일
Look at your code,
ymax= @ (xx)5.*sin(pi.*xx./10);
Anonymous function. Okay so far.
syms xx
Symbolic declaration. Okay so far.
hy=ymax(xx)/round(ymax(xx)/hx);
Applying the anonymous function to the symbolic value -- dubious. Expecting to be able to round() the result of the symbolic calculation: very dubious. These are not impossible but are unlikely (there are some uses for passing a symbolic value to an anonymous function.)
y=[0:hy:ymax(xx)] ;
Clearly broken. hy is symbolic, ymax(xx) is symbolic, and you cannot use the colon operator with symbolic bounds.
Unfortunately there is a shortage of comments about the purpose of that section of code...
댓글 수: 1
Philip Baczek
2016년 2월 27일
편집: Philip Baczek
2016년 2월 27일
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!