Question

In: Computer Science

Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval...

Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval 0 to 360.

function de=equivalent(d) For example, equivalent(540) = 180 equivalent(-30) = 330

Solutions

Expert Solution

File name:- equivalent.m

Matlab program:- in Editor

function de=equivalent(d)       %d is input for function in degrees
    if(d<0)
        while(d<0)
            d=360+d;        %while d is lessthan zero add 360 for d
        end
    end
    if(d>360)
        while(d>360)
            d=d-360;        %while d is greaterthan zero substract 360 from d
        end
    end
    de=d;       %return the remaining d
end


Output:- in Command window

>> de=equivalent(550)

de =

   190

>> de=equivalent(540)

de =

   180

>> de=equivalent(-30)

de =

   330

>> de=equivalent(90)

de =

    90

>>


Related Solutions

Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs:...
Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs: a list of time values a list of position values a single time value. Output: a single number which is obtained by numerically differentiating position with respect to time twice (forward difference method) and then interpolating the results based on the third input. Example: time=0:10; position=time.^3; myaccel(time,position,2.8) % should return 22.8
Write a function file that accepts each of the four vectors as inputs. The function file...
Write a function file that accepts each of the four vectors as inputs. The function file should plot the data on different graphs in the same window. You need to add axis labels and graph titles. time- 0 5 10 15 20 25 30 A1- 0 7 11 19 15 14 7 A2- 0 10 15 21 16 11 13 A3- 0 9 13 17 22 25 21
Write a MATLAB function, called arbpoly, that computes a polynomial arbitrary nth degree. The function will...
Write a MATLAB function, called arbpoly, that computes a polynomial arbitrary nth degree. The function will take 2 inputs: 1) the first input will be a row vector, c, containing the coefficients of the polynomial, starting with the coefficient of the highest - degree term; 2) the second input will be a scalar, x, which is a real number at which the polynomial will be evaluated. The function's only output, y, will be the scalar value of the polynomial computed...
Write a MATLAB function [p, z] = proj(A,b) that computes the projection of b onto the...
Write a MATLAB function [p, z] = proj(A,b) that computes the projection of b onto the Column Space of an m × n matrix A. Your program should allow for the possibility that the columns of A are not linearly independent. In order for the program to work, you will need to create a basis for Col A.
Write a MATLAB function that accepts input vector x and returns the number of local maximums...
Write a MATLAB function that accepts input vector x and returns the number of local maximums of x with value between xmin and xmax. Ask user to input values xmin and xmax at the beginning of the procedure. Use vector x (the vector x from that file consists of 1000 numbers ranging from 0.0044 to 0.67).
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an output, A1. The output A1 should be the area under a curve, f(x), for x starting at x_start and ending at x_end. The input r should be a vector (array) having x_start and x_end as its two elements. The input N should be an integer equal to the number of equallength sub-intervals in which the interval from x_start to x_end should be divided. Here,...
Write a MATLAB function that will generate chi-square random variables with v degrees of freedom by...
Write a MATLAB function that will generate chi-square random variables with v degrees of freedom by generating v standard normal, squaring them and then adding them up. This uses the fact that is chi-square with v degrees of freedom. Generate some random variables and plot in a histogram. The degrees of freedom should be an input argument set by the user.
[Lumley] Write an R function that takes inputs n1, n2, N1, N2, σ12,σ2and computes the variance...
[Lumley] Write an R function that takes inputs n1, n2, N1, N2, σ12,σ2and computes the variance of the population total in a stratified sample. Choose some reasonable values of the population sizes and variances, and graph this function as n1 and n2 change, to find the optimum and to examine how sensitive the variance is the precise values of n1 and n2.
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one vector v (either a column or a row) and outputs the same vector v of the same dimensions, but with the values in reverse order (use MATLAB function flip()). In other words, v will be overwritten by its flipped version. In your function, you may only use length() and floor(). You only need one loop. %this code tests the function, myflip, which you will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT