Question

In: Computer Science

Using Matlab, write a function that takes numeric data as its input argument and prints a...

Using Matlab, write a function that takes numeric data as its input argument and prints a message to the Command Window stating if the number is positive, or negative, or 0. This function should transfer an output value to the Workspace ONLY when the input value is negative.

Please include a copiable code and the associated screenshots.

Solutions

Expert Solution

Let us step by step implement funciton following given points in question,

Step 1. Check if numeric data entered: To check for numeric input we can use isnumeric function.

if(isnumeric(input_to_function)) 
    % numeric entered now proceed to next step
else 
    disp('please enter numeric input');
end

Step 2. prints a message to the Command Window stating if the number is positive, or negative, or 0.

function output_value = check_number(x)
    if(isnumeric(x)) 
        % numeric entered now proceed to next step
        if x>0 
            % number greater than 0 display positve
            disp('Positive'); 
        
        elseif x<0 
            % check if number less than 0, that is negative
            % transfer output to workspace
            disp('Negative') 
            
        else
            disp('Zero'); 
        end
        %end of if statement
    
    else 
        % number not numeric
        disp('please enter numeric input');
    end

    
end

Step 3: This function should transfer an output value to the Workspace ONLY when the input value is negative. we simply pass output_value with input_parameter in our case x.

Final Solution:

function output_value = check_number(x)
    if(isnumeric(x)) 
        % numeric entered now proceed to next step
        if x>0 
            % number greater than 0 display positve
            disp('Positive'); 
        
        elseif x<0 
            % check if number less than 0, that is negative
            % transfer output to workspace
            disp('Negative') 
            output_value = x;
        else
            disp('Zero'); 
        end
        %end of if statement
    
    else 
        % number not numeric
        disp('please enter numeric input');
    end
end

Output:


Related Solutions

Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
Write a C function str_to_float() that takes a numeric string as input and converts it to...
Write a C function str_to_float() that takes a numeric string as input and converts it to a floating point number. The function should return the floating point number by reference. If the conversion is successful, the function should return 0, and -1 otherwise (e.g. the string does not contain a valid number). The prototype of the function is given below int str_to_float(char * str, float * number);
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with information about the total amount owed and how much the tip was. As a reminder, the tip amounts are 10%, 15% and 20% for stingy, regular, and generous customers. And the tax amount should be 7%. The total amount is calculated as the sum of two amounts: check_amount = base_cost*1.07 tip_amount = tip_percentage*check_amount To receive full credit, you must use string...
Write a function bracket_by_len that takes a word as an input argument and returns the word...
Write a function bracket_by_len that takes a word as an input argument and returns the word bracketed to indicate its length. Words less than five characters long are bracketed with << >>, words five to ten letters long are bracketed with (* *), and words over ten characters long are bracketed with /+ +/. Your function should require the calling function to provide as the first argument, space for the result, and as the third argument, the amount of space...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
Write a MATLAB function named numberWords() that takes a whole number as an argument and returns...
Write a MATLAB function named numberWords() that takes a whole number as an argument and returns a string containing the number word for the whole numbers 0 - 999. For example:  numberWords(234) would return 'two hundred thirty-four' If the input value is not a whole number between 0 - 999 then the function should return a string equivalent to 'ERROR'.
In Java, write a recursive function that accepts a string as its argument and prints the...
In Java, write a recursive function that accepts a string as its argument and prints the string in reverse order. Demonstrate the function in a driver program.
Write a recursive function (using Matlab) moreFactors(a,b,fact) that does the following: 1. Takes as an input...
Write a recursive function (using Matlab) moreFactors(a,b,fact) that does the following: 1. Takes as an input 3 positive integers. 2. Of the two integers a and b, the function returns the integer that has the most factors fact. 3. If both integers a and b have the same amount of factors fact, the function will return the larger integer. Test your function with the following: >> result=moreFactors(24,32,3) result = 24 (24 = 3^1 · 2^3 , 32 = 2^5 )...
Write a function using MATLAB that will accept a structure as an argument and return two...
Write a function using MATLAB that will accept a structure as an argument and return two cell arrays containing the names of the fields of that structure and the data types of each field. Be sure to check that the input argument is a structure, and generate an error message if it is not.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT