Cannot compute number of steps
Ältere Kommentare anzeigen
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 Kommentare
John D'Errico
am 26 Feb. 2016
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
am 26 Feb. 2016
Philip Baczek
am 26 Feb. 2016
Bearbeitet: Walter Roberson
am 26 Feb. 2016
Antworten (1)
Walter Roberson
am 26 Feb. 2016
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 Kommentar
Philip Baczek
am 27 Feb. 2016
Bearbeitet: Philip Baczek
am 27 Feb. 2016
Kategorien
Mehr zu Calculus finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!