
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
- The following relates to Problems 4 and 5. Christchurch, New Zealand experienced a major earthquake on February 22, 2011. It destroyed 100,000 homes. Data were collected on a sample of 300 damaged homes. These data are saved in the file called CIEG315 Homework 4 data.xlsx, which is available on Canvas under Files. A subset of the data is shown in the accompanying table. Two of the variables are qualitative in nature: Wall construction and roof construction. Two of the variables are quantitative: (1) Peak ground acceleration (PGA), a measure of the intensity of ground shaking that the home experienced in the earthquake (in units of acceleration of gravity, g); (2) Damage, which indicates the amount of damage experienced in the earthquake in New Zealand dollars; and (3) Building value, the pre-earthquake value of the home in New Zealand dollars. PGA (g) Damage (NZ$) Building Value (NZ$) Wall Construction Roof Construction Property ID 1 0.645 2 0.101 141,416 2,826 253,000 B 305,000 B T 3…arrow_forwardRose Par posted Apr 5, 2025 9:01 PM Subscribe To: Store Owner From: Rose Par, Manager Subject: Decision About Selling Custom Flower Bouquets Date: April 5, 2025 Our shop, which prides itself on selling handmade gifts and cultural items, has recently received inquiries from customers about the availability of fresh flower bouquets for special occasions. This has prompted me to consider whether we should introduce custom flower bouquets in our shop. We need to decide whether to start offering this new product. There are three options: provide a complete selection of custom bouquets for events like birthdays and anniversaries, start small with just a few ready-made flower arrangements, or do not add flowers. There are also three possible outcomes. First, we might see high demand, and the bouquets could sell quickly. Second, we might have medium demand, with a few sold each week. Third, there might be low demand, and the flowers may not sell well, possibly going to waste. These outcomes…arrow_forwardConsider the state space model X₁ = §Xt−1 + Wt, Yt = AX+Vt, where Xt Є R4 and Y E R². Suppose we know the covariance matrices for Wt and Vt. How many unknown parameters are there in the model?arrow_forward
- Business Discussarrow_forwardYou want to obtain a sample to estimate the proportion of a population that possess a particular genetic marker. Based on previous evidence, you believe approximately p∗=11% of the population have the genetic marker. You would like to be 90% confident that your estimate is within 0.5% of the true population proportion. How large of a sample size is required?n = (Wrong: 10,603) Do not round mid-calculation. However, you may use a critical value accurate to three decimal places.arrow_forward2. [20] Let {X1,..., Xn} be a random sample from Ber(p), where p = (0, 1). Consider two estimators of the parameter p: 1 p=X_and_p= n+2 (x+1). For each of p and p, find the bias and MSE.arrow_forward
- 1. [20] The joint PDF of RVs X and Y is given by xe-(z+y), r>0, y > 0, fx,y(x, y) = 0, otherwise. (a) Find P(0X≤1, 1arrow_forward4. [20] Let {X1,..., X} be a random sample from a continuous distribution with PDF f(x; 0) = { Axe 5 0, x > 0, otherwise. where > 0 is an unknown parameter. Let {x1,...,xn} be an observed sample. (a) Find the value of c in the PDF. (b) Find the likelihood function of 0. (c) Find the MLE, Ô, of 0. (d) Find the bias and MSE of 0.arrow_forward3. [20] Let {X1,..., Xn} be a random sample from a binomial distribution Bin(30, p), where p (0, 1) is unknown. Let {x1,...,xn} be an observed sample. (a) Find the likelihood function of p. (b) Find the MLE, p, of p. (c) Find the bias and MSE of p.arrow_forwardGiven the sample space: ΩΞ = {a,b,c,d,e,f} and events: {a,b,e,f} A = {a, b, c, d}, B = {c, d, e, f}, and C = {a, b, e, f} For parts a-c: determine the outcomes in each of the provided sets. Use proper set notation. a. (ACB) C (AN (BUC) C) U (AN (BUC)) AC UBC UCC b. C. d. If the outcomes in 2 are equally likely, calculate P(AN BNC).arrow_forwardSuppose a sample of O-rings was obtained and the wall thickness (in inches) of each was recorded. Use a normal probability plot to assess whether the sample data could have come from a population that is normally distributed. Click here to view the table of critical values for normal probability plots. Click here to view page 1 of the standard normal distribution table. Click here to view page 2 of the standard normal distribution table. 0.191 0.186 0.201 0.2005 0.203 0.210 0.234 0.248 0.260 0.273 0.281 0.290 0.305 0.310 0.308 0.311 Using the correlation coefficient of the normal probability plot, is it reasonable to conclude that the population is normally distributed? Select the correct choice below and fill in the answer boxes within your choice. (Round to three decimal places as needed.) ○ A. Yes. The correlation between the expected z-scores and the observed data, , exceeds the critical value, . Therefore, it is reasonable to conclude that the data come from a normal population. ○…arrow_forwardding question ypothesis at a=0.01 and at a = 37. Consider the following hypotheses: 20 Ho: μ=12 HA: μ12 Find the p-value for this hypothesis test based on the following sample information. a. x=11; s= 3.2; n = 36 b. x = 13; s=3.2; n = 36 C. c. d. x = 11; s= 2.8; n=36 x = 11; s= 2.8; n = 49arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Trigonometry (MindTap Course List)TrigonometryISBN:9781337278461Author:Ron LarsonPublisher:Cengage LearningAlgebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageAlgebra 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



