USE MATLAB TO ANSWER: Write a function file called coord_convert.m that converts
ID: 3714541 • Letter: U
Question
USE MATLAB TO ANSWER:
Write a function file called coord_convert.m that converts rectangular coordinates to polar coordinates or vice versa.
• There should be 3 inputs to coord_convert.m: coordinates a and b and a character string called coord that has the value ’rectangular’ if the input coordinates are rectangular coordinates or ’polar’ if the input coordinates are polar coordinates.
• There should be 2 outputs from coord_convert.m: coordinates c and d in the new coordinate system. The values of c and d should be calculated as described in Appendix A.
• If coord is anything other than ’rectangular’ or ’polar’ the values of the outputs c and d should both be set equal to NaN
• Be sure to include comments describing the function and its inputs and output.
Appendix A - Coordinate Conversion Formulas If the input coordinates a and b are rectangular coordinates, calculate the corresponding polar coordinates as follows. tan-(b/a)if a >0 ? + tan-1 (b/a) if a 0 if a0 and bExplanation / Answer
function [c,d]=coord_convert(a,b,coord) %function [c,d]=coord_convert(a,b,coord) %inputs: %a,b:coordinates %coord:a character vector that has the value 'rectanguar' or 'polar' %outputs %c,d:coordinates in the new system if strcmp(coord,'rectangular') c=sqrt(a*a+b*b); if a>0 d=atan(b/a); elseif a0 d=pi/2; elseif a==0 && b=0 c=a*cos(b); d=a*sin(b); else c=NaN; d=NaN; end else c=NaN; d=NaN; endRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.