
Concept explainers
To write:
A program to convert the Cartesian coordinates to spherical coordinates, and print the results.
Answer to Problem 15E
Solution:
The script file is,
% MATLAB code to print the result in spherical coordinates.
%script file.
[x, y, z] = getcartesian();
%get the value of cartesian coordinates by calling the
%getcartesian.
printspherical(x, y, z)
%print the value in spherical coordinates by calling the function
%printspherical.
% end of script
%The script file should be placed in the same folder.
The function file is,
% MATLAB code to get the result in cartesian coordinates.
%Function file.
function [x, y, z] = getcartesian()
%get the cartesian coordinates by using the function getcartesian.
x = 1;
%define the variable x.
y = 2;
%define the variable y.
z = 3;
%define the variable z.
end
% end of function
%The function file should be placed in the same folder.
The function file is,
% MATLAB code to print the result in spherical coordinates.
%Function file.
function printspherical(x, y, z)
%the spherical coordinates will be printed by using the function
%printspherical.
[rad, incl, azi] = convert2spher(x, y, z);
%convert the spherical coordinates to cartesian coordionates.
fprintf('the radius is %.2f\n', rad);
%print the radius.
fprintf('the inclination angle is %.2f\n', incl);
%print the inclination angle.
fprintf('the azimuth angle is %.4f\n', azi);
%print the azimuth.
end
% end of function
function [ra, in, a] = convert2spher(x, y, z)
%call a subfunction convert2spher to transform the cartesian coordinates
%into spherical coordinates.
ra = sqrt(x^2+y^2+z^2);
%define the radius.
in = acos(z/ra);
%define the inclination angle.
a = atan(y/z);
%define the azimuth angle.
end
%The function file should be placed in the same folder.
Explanation of Solution
Consider the Cartesian coordinates are,
The spherical coordinates are
The formulas to convert the Cartesian coordinates to spherical coordinates are as follows.
Substitute 1 for
The inclination angle is,
The azimuth angle is,
The spherical coordinates are
MATLAB Code:
% MATLAB code to print the result in spherical coordinates.
%script file.
[x, y, z] = getcartesian();
%get the value of cartesian coordinates by calling the function
%getcartesian.
printspherical(x, y, z)
%print the value in spherical coordinates by calling the function
%printspherical.
% end of script
%The script file should be placed in the same folder.
% MATLAB code to get the result in cartesian coordinates.
%Function file.
function [x, y, z] = getcartesian()
%get the cartesian coordinates by using the function getcartesian.
x = 1;
%define the variable x.
y = 2;
%define the variable y.
z = 3;
%define the variable z.
end
% end of function
%The function file should be placed in the same folder.
% MATLAB code to print the result in spherical coordinates.
%Function file.
function printspherical(x, y, z)
%the spherical coordinates will be printed by using the function
%printspherical.
[rad, incl, azi] = convert2spher(x, y, z);
%convert the spherical coordinates to cartesian coordionates.
fprintf('the radius is %.2f\n', rad);
%print the radius.
fprintf('the inclination angle is %.2f\n', incl);
%print the inclination angle.
fprintf('the azimuth angle is %.4f\n', azi);
%print the azimuth.
end
% end of function
function [ra, in, a] = convert2spher(x, y, z)
%call a subfunction convert2spher to transform the cartesian coordinates
%into spherical coordinates.
ra = sqrt(x^2+y^2+z^2);
%define the radius.
in = acos(z/ra);
%define the inclination angle.
a = atan(y/z);
%define the azimuth angle.
end
%The function file should be placed in the same folder.
Save the MATLAB script with name, paracscript.m and function files with names printspherical.m and getcartesian.m in the current folder. Execute the program by typing the script name at the command window to generate result.
Result:
The result is,

Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 6 Solutions
Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
- Search A random sample of n₁ =217 people who live in a city were selected and 107 identified as a "student". A random sample of n₂ =109 people who live in a rural area were selected and 66 identified as a "student". Find the 98% confidence interval for the difference in the proportion of people that live in a city who identify as a "student" and the proportion of people that live in a rural area who identify as a "student." a. The point estimate for difference in population proportions (City group minus Rural Area group) = Round answers to 3 decimal places. -0.112 b. Fill in the blanks of the following statement. Round answers to 3 decimal places. We are 98 0% confident that the difference in population proportion of people who identified as a "student" in city and rural area falls between -0.247 0.022 0.022 and c. Select the correct conclusion based on the above confidence interval. O Since the above confidence interval gives only negative values, we have 98% confident that the…arrow_forwardCould you please provide solutions to the follwoing questions.Thanksarrow_forwardsearch A random sample of ni A random sample of n₂ "student". 217 people who live in a city were selected and 107 identified as a "student". 109 people who live in a rural area were selected and 66 identified as a Find the 98% confidence interval for the difference in the proportion of people that live in a city who identify as a "student" and the proportion of people that live in a rural area who identify as a "student." a. The point estimate for difference in population proportions (City group minus Rural Area group) = Round answers to 3 decimal places. -0.112 b. Fill in the blanks of the following statement. Round answers to 3 decimal places. We are 98 0% confident that the difference in population proportion of people who identified as a "student" in city and rural area falls between -0.247 ✔and 0.022 0.022 c. Select the correct conclusion based on the above confidence interval. Since the above confidence interval gives only negative values, we have 98% confident that the…arrow_forward
- Could you please help me answer parts b,d and e. Thanksarrow_forwardה The state of CT claims that the average time on death row is 15 years. A random survey of 75 death row inmates revealed that the average length of time on death row is 17.7 years with a standard deviation of 6.2 years. Conduct a hypothesis to test the state of CT's claim. What type of test should be run? t-test of a mean Oz-test of a proportion The alternative hypothesis indicates a two-tailed test O right-tailed test O left-tailed test Calculate the p-value. (Round properly to 4 decimal places) What is the decision? O We fail to reject the claim that the average time on death row is 15 years We reject the claim that the average time on death row is 15 years Submit Question F4 F3 F2 W E 14 POS UP T DELL F5 F6 F7 F8 F9 F10 F11 711 5 dos % $ 54 Οι 6 R T Y & 7arrow_forwardDon't answer without proper knowledge of this statistics and probability question.arrow_forward
- I need help in this statistics question don't answer without proper knowledge.arrow_forwardPx in decimal or integer value?arrow_forwardCounting Rules: a. The PSU's Mixed Me club has 32 members. You need to pick a different person for each of the following positions: president, treasurer, and secretary from the 32 members. How many different ways can you do this? b. How many ways can you choose 6 cookies from a cookie jar containing 16 cookies of all the same type? c. How many ways can you make a 6 digit password that can be any number (including zero) or letter (not case sensitive)? d. How many ways can you order 4 people standing in line? Check Answerarrow_forward
- Suppose a small company that manufactures cereal bars own two scales that weigh their products (say A and B). Quality control manager in this company is concerned that scale A is erroneous. He takes a sample of 20 cereal bars and weigh each of them using both scales A and B. Assume that you were given a spread sheet that include weights of the 20 cereal bars reported by two scales. Explain how you would approach testing the QC managers’ concern. What type of tests/CI you would construct to help him make a decision? Mention of any assumptions you would check or any graphing techniques you would use to display the data.arrow_forwardMatch the name of the sampling method descriptions given. choosing every 5th person on a list Situations separating all students by grade level, and selecting 10 students from each grade pulling 50 names from a hat randomly select two tables in the cafeteria and survey all the people at those two tables ask all the students in your math class Sampling Method a. Stratified b. Simple Random c. Convenience d. Systematic e. Cluster Submit Question II F3 <40 F4 144 $ F5 114 UP T DELL F6 F7 F8 F9 % olo &arrow_forwardthis question below Are there less children diagnosed with Autism Spectrum Disorder (ASD) in states that have larger urban areas over states that are mostly rural? Assume data were collected from a fairly urban state and they found 189 eight-year olds diagnosed with ASD out of 19300 eight-year olds evaluated. D Assume data were then collected for a fairly rural state and they found 70 eight-year olds diagnosed with ASD out of 2841 eight-year olds evaluated. Is there enough evidence to show that the proportion of children diagnosed with ASD in the fairly urban state is lower than the proportion in the fairly rural state? a.) Test at the 4% level b.) Compute a 96% confidence interval for the difference in proportions. Use the following steps for the hypothesis test. For the confidence interval you do not need to do all the steps since you did some of them already in hypothesis test. Part a.) HYPOTHESIS TEST Parameter What is the correct parameter symbol and wording for population 1? P1…arrow_forward
Trigonometry (MindTap Course List)TrigonometryISBN:9781337278461Author:Ron LarsonPublisher:Cengage LearningAlgebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage
Algebra and Trigonometry (MindTap Course List)AlgebraISBN:9781305071742Author:James Stewart, Lothar Redlin, Saleem WatsonPublisher:Cengage Learning
Mathematics For Machine TechnologyAdvanced MathISBN:9781337798310Author:Peterson, John.Publisher:Cengage Learning,
Trigonometry (MindTap Course List)TrigonometryISBN:9781305652224Author:Charles P. McKeague, Mark D. TurnerPublisher:Cengage Learning



