Question: Please provide the matlab code for the following problem. the XYZ file is shown as follows: please submit the function file fn_printspherical.m script file CartSpher.m


), In 3D space, the Cartesian coordinates (x,y,z) can be converted to spherical coordinates (radius r, polar angle, e, azimuth angle, 6) by the following equations: r = 7x2 + y2 + z2, = cos -1 = = tan-1 1. Write a function fn_printspherical that prints the Cartesian coordinates (x,y,z) and corresponding spherical coordinates, (r,0,0). The function fn_printspherical calls a subfunction fn_convert2spher that converts from Cartesian to spherical coordinates. 2. Write a script, CartSpher that reads the Cartesian coordinates from an external file, convert to spherical coordinate, and print the results. When the script reads the Cartesian coordinates from a file, assume that x, y, z are saved in matrix, thus fn_printspherical should be in the loop to print all the results. Here is the requirement for the script: XYZ.txt 8.1 9.1 1.3 1.6 9.7 6.6 0.4 9.6 8.5 9.3 4.9 9.1 6.3 8 6.8 Read the file (XYZ.txt) by using the following function -input (Let user input file name) -load (read the file that user input) When you load the data, assign the data values to the matrix variable. Use this matrix variable as input variable(s) to the function, fn_printspherical Display should follow the below format 1 1.4 7.6 7.4 2.8 4.2 3.9 5.5 9.6 9.6 9.2 7.9 9.6 6.6 1.7 >> CartSpher Enter the file name with file extension: XYZ.txt Cartesian Coordinate: (x, y, z)=[8.10, 1.60, 6.60): The radius is 10.57 The inclination angle is 0.90 The azimuth angle is 0.20 8.1000000e+00 9.1000000e+00 1.3000000e +00 9.1000000e+00 6.3000000e+00 1.0000000e+00 2.8000000e+00 5.5000000e+00 9.6000000e+00 9.6000000e+00 1.6000000e+00 9.7000000e+00 9.6000000e+00 4.9000000e+00 8.0000000e+00 1.4000000e +00 4.2000000e+00 9.2000000e+00 7.9000000e+00 9.6000000e+00 6.6000000e+00 4.0000000e-01 8.5000000e+00 9.3000000e+00 6.8000000e+00 7.6000000e+00 7.4000000e+00 3.9000000e+00 6.6000000e+00 1.7000000e+00
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
