Cannot compute number of steps
Afficher commentaires plus anciens
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 commentaires
John D'Errico
le 26 Fév 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
le 26 Fév 2016
Philip Baczek
le 26 Fév 2016
Modifié(e) : Walter Roberson
le 26 Fév 2016
Réponses (1)
Walter Roberson
le 26 Fév 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 commentaire
Philip Baczek
le 27 Fév 2016
Modifié(e) : Philip Baczek
le 27 Fév 2016
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!