Not enough input arguments in trapz

8 views (last 30 days)
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 Comment
Catalytic
Catalytic on 2 Jul 2023
Edited: Catalytic on 2 Jul 2023
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)
P_1 = 239.0549

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 2 Jul 2023
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.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!