Q1 Write a Matlab function called spher2cart that will conve
Q1) Write a Matlab function called spher2cart that will convert Spherical coordinates to Cartesian coordinates. Note that this function will have three inputs and three outputs. Test you function using spherical coordinates : ( ( 2, ¾ , ¾ ). For this program, once it works, add the nargin commands to check for correct number of inputs and write appropriate messages.
Solution
Solution :
%**********************************function here*************************************
function [ x , y, z ] = spher2cart( r ,theta,phi )
if nargin <3
error(\'Insufficient number of arguments.Please provide 3 arguments\');
end
if nargin == 3
x = r*cos(theta)*sin(phi);
y = r*sin(theta)*sin(phi);
z = r *cos(phi);
end
end
%********************************************end*******************
