Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is in matlab if you cant view images, right click it and click disp

ID: 3810477 • Letter: T

Question

This program is in matlab

if you cant view images, right click it and click display in new tab

ES 201 Spring 2017- Week 10 Homework Due: 9:30 am Tuesday 04/04/2017 Learning objectives 10 Write a function that accepts variable number of arguments 10 Write a function that returns multiple arguments Use nargin statement 10 Use switch statements Use nested for loop Use sprintf Cor fprintf) for formatted output to the screen Create an array and rearrange it 10 10 Use isnan Instructions You will have two problems to solve for this week. Question 1 Instructions The Cartesian and Spherical coordinates can be converted to each other using the following equations: 0 arccos arccos arctan Source Create a function named spherical coordinate. m to convert the Cartesian coordinate to Spherical coordinate system that gets three input parameters. Then use nargin statement to identify the number of inout parameters entered by the user. Using switch statement, set the value of y30 and z 0 if only the value of x is entered. If the value of x and y are entered and value of z is missing, set z 0. Then use the above mentioned conversions to convert the coordinates system and display the result with 2 decimals Sample output: spherical coordinate (2, 10) spherical coordinate (2) r: 10.20 r 2.00 theta: 1.5 theta 57 phi: 1.37 phi 0.00

Explanation / Answer

Que1 Matlab code:

function [r,theta, phi] = spherical_coordinates(x,y,z)
switch nargin
case 3
r = sqrt(x^2 + y^2 + z^2);
theta = acos(z/r);
phi = atan(y/x);
case 2
z = 0;
r = sqrt(x^2 + y^2 + z^2);
theta = acos(z/r);
phi = atan(y/x);
case 1
y = 0;
z = 0;
r = sqrt(x^2 + y^2 + z^2);
theta = acos(z/r);
phi = atan(y/x);
otherwise
r = 0;theta = 0; phi = 0;
end
end

Sample Output:

Que 2 Matlab code:

clc;
clear all;
n = input('Enter a number')
arr = [];
arr = 2:n;
for i = 2:n
for j = i+1:n-1
if( mod(arr(j),i) == 0)
arr(j) = NaN;
end
end
end
primes = [];
for j = 1:n-1
if(isnan(arr(j)))

else
primes = [primes; arr(j)];   
end
end
primes

Sample Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote