0

I want to implement this equation of spherical coordinates in matlab, but I am really confused how to get the value of j1 from it. and what values of phie1 and theeta1 should i define?

j1 = (cos(ø1)cos(∅1) , cos(ø1)sin(θ1) , sin(ø1))T

while I implemented like this but it gives error :

phiie1 = 0:180;
theeta1= 0:360;
j1 = transpose([(cos(phiie1)*(cos(theeta1))) (cos(phiie1)*(sin(theeta1))) sin(phiie1)]) %eq 4 
Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Take a look at built-in functions `cart2sph` and `sph2cart`. – aosborne Mar 08 '21 at 21:15
  • 1
    It looks like you have specified `phi` and `theta` in degrees. In MATLAB, `sin` and `cos` use units of radians. If you want to use degrees, you can use the `sind` and `cosd` functions instead. – Harry Mar 08 '21 at 22:51
  • Also, in MATLAB, `*` will typically do [matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication). If you have two matrices (or vectors) that you want to multiply element-by-element, then you should use the `.*` operator instead. – Harry Mar 08 '21 at 22:54
  • And finally, if you want to multiply two matrices (or vectors) element-by-element, then they should have the same sizes. However, your `phi` and `theta` have different sizes. You can check this by executing `size(phiie1)` and `size(theeta1)`. This is probably the source of your error message (but you should always include your error message in your question). – Harry Mar 08 '21 at 22:57
  • The other thing you need to think about is the shape of the matrix `j1`. If you just calculated `j1` for one value of `(theta, phi)`, then `j1` would be a `(3 x 1)` vector. However, it looks like you want to calculate `j1` for many combinations (say `N`) of `(theta, phi)`. In that case, `j1` should be a `(3 x N)` matrix. In MATLAB, you can stack row vectors using syntax like this: `[row1; row2; row3]`. – Harry Mar 08 '21 at 23:07

0 Answers0