Not enough input arguments in trapz
8 次查看(过去 30 天)
显示 更早的评论
I am currently trying to perfor, numerical integration inb polar coordinates. I used trapz function this way:
Nx = 402;
x = linspace(-L/2,L/2, Nx);
y = linspace(-L/2, L/2, Ny);
[X,Y] = meshgrid(x(2:end-1), y(2:end-1));
[TH,R] = cart2pol(X,Y);
alpha_1 = linspace(0, pi/5, Nx-2);
ro = linspace(0, 20, Nx-2);
P_1 = trapz(alpha_1, (trapz(ro, (abs(v).*R), 2)),1);
v is a complex valued (400,400) matrix with non zero elements. I wanted to find volume under this function within angle pi/5 (special region in my task). But I came across an error: Not enough input arguments in line with trapz(). Where is the mistale, I checked documentation, everything should be fine. I tried to remove dim = 1 in outer integral - got same error.
1 个评论
Catalytic
2023-7-2
编辑:Catalytic
2023-7-2
Please provide code that can demonstrate the error and then run it for us like I've done below. As you can see, when I run your code with fabricated values, I get a value for P_1 with no error messages.
Nx = 402;Ny=402; v=rand(400); L=100;
x = linspace(-L/2,L/2, Nx);
y = linspace(-L/2, L/2, Ny);
[X,Y] = meshgrid(x(2:end-1), y(2:end-1));
[TH,R] = cart2pol(X,Y);
alpha_1 = linspace(0, pi/5, Nx-2);
ro = linspace(0, 20, Nx-2);
P_1 = trapz(alpha_1, (trapz(ro, (abs(v).*R), 2)),1)
采纳的回答
John D'Errico
2023-7-2
I would strongly suggest you should not name your own functions the same as existing code. If you do, then this is exactly the type of error you should expect. To learn if what I suspect is true, do this at the command line.
which trapz -all
It should show a function named trapz that you wrote. If so, then rename your function.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!