- placed the first term r.^2 in parenteses
- Added a dot in front of the first sin()
- added a dot in front of the last division operator
- added parentheses to the last term as below:
I can not find an error in the expression
조회 수: 3(최근 30일)
I'm new to matlab, so sorry for the stupid question.
I tried to fix the errors, but could not find another. I give the code of the expression that I want to get in Python and ask to fix this expression for matlab. Also, if not difficult, please share some good materials for learning matlab.
In MatLab with error:
fun = @(r,t,p) r.^2*sin(p).*(exp(i*(r.*sin(t).*cos(p) + r.*sin(t).*sin(p) + r.*cos(t))))*4*pi/(r.^2 - 4)
q = integral3(fun,0,1.99,0,pi,0,pi*2)
Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To
perform elementwise multiplication, use '.*'.
Katie 2019년 10월 24일
Hi! It looks like you're really close! You're just missing a couple dots in front of some of your multiplication and division operators. Below is the fixed expression. I also added in a couple sets of parentheses.
fun = @(r,t,p) (r.^2).*sin(p).*(exp(i*(r.*sin(t).*cos(p) + r.*sin(t).*sin(p) + r.*cos(t)))).*((4*pi)./(r.^2 - 4))
Summary of changes:
Jim Riggs 2019년 10월 24일
편집: Jim Riggs 2019년 10월 25일
It's hard to say without seeing how the variables r, t, and p are defined. If r and p are vectors of different length, then the expression:
will cause a problem, because it implies a matrix multiplication of a vector of length r and one of length p. (here r.^2 is a vector with the same length as r, and sin(p) is a vector with the same length as p)
In Matlab, if you want to multiply vector r and vector p, they both must be the same length, and one must be a row vector, and the other a column vector. For example, if r and p are the same size but both are row vectors, then r*p will give an error (This works in python, but not in matlab, although in python, this will perform element-wise multiplication). To perform the matrix multiply in matlab you would have to transform one of them:
If you want to perform element-wise multiplication, r and p must still be the same length, and you use .*