Question

1. Write a function called testneg with one input and no outputs. The function will test to see if the input value is negativ

math lab

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(Question 1) MATLAB Script:

close all
clear
clc

fprintf('Test 1\n------------------------\n')
n = 10
testneg(n)

fprintf('\nTest 2\n------------------------\n')
n = -5
testneg(n)

function testneg(n)
if n < 0
fprintf('Warning: The input value %.2f is negative.\n', n)
end
end

Output:

Test 1
------------------------
n =
10

Test 2
------------------------
n =
-5
Warning: The input value -5.00 is negative.

Add a comment
Know the answer?
Add Answer to:
math lab 1. Write a function called testneg with one input and no outputs. The function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function called testneg with one input and no outputs. The function will test to...

    Write a function called testneg with one input and no outputs. The function will test to see if the input value is negative. If it is negative, use fprintf to print the message to the screen Warning: The input value n is negative. where n is not literally the letter n, but is the value of the input to the function. Assume the input value is a floating-point number, so use an appropriate format in the fprintf to print the...

  • Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes...

    Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes as argument an integer corresponding to a number of seconds, computes the exact time in hours, minutes and seconds, then prints the following message to the screen: <inputseconds> seconds corresponds to: <hour> hours, <minute> minutes and <second> seconds Write another method called in Seconds that takes as arguments three integers: hours, minutes and seconds, computes the exact time in seconds, then returns the total...

  • o Write a function that outputs even numbers less than the input number. • Function name...

    o Write a function that outputs even numbers less than the input number. • Function name should be 'evenprint'. • A number is given as input to the function. . The function must return a list of even numbers def evenprint(num): #write statement >[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74,...

  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • (Matlab) Suppose we have a function “hw5f.m” that takes as input x and outputs the value for a function f(x). Write a Matlab program that inputs: • interval [a, b]; • m, the number of data points wit...

    (Matlab) Suppose we have a function “hw5f.m” that takes as input x and outputs the value for a function f(x). Write a Matlab program that inputs: • interval [a, b]; • m, the number of data points with evenly spaced nodes from x1 = a to xm = b, and values from f(x); • location z satisfying x2 < z < xm−1, where h = (b − a)/(m − 1); and outputs the value of the interpolaton polynomial using only...

  • c++ please (1) Write a program that prompts the user to enter an integer value N...

    c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...

  • This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an...

    This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an integer number n, and returns a matrix that is nxn, where the value of each number is the distance from the upper-left to bottom-right diagonal. (Use while loops if you can!) Numbers below the diagonal should be negative, and numbers above the diagonal should be positive. For example, if your input was 5, your output would be: 0 1 2 3 4 -1 0...

  • Write a function to calculate the sum of the reciprocals of a series of odd numbers....

    Write a function to calculate the sum of the reciprocals of a series of odd numbers. The function will have one input and no output, with the input being the ending value for the series of odd values. Write the function definition statement Initialize a variable to zero. This variable will contain the sum of all the values. Create a for loop that loops over all odd numbers from 1 to the specified ending value. Inside the loop, add the...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • Write a program in C++. You need everything everythihng given You will create a function that...

    Write a program in C++. You need everything everythihng given You will create a function that validates input. It should accept only non-negative integers. If the input is incorrect the function should throw an exception. The exception will not be caught in the function. You will create a function that reads in 2 integer values. One is a number that will be raised to the power of the second. So if 5 and 6 are entered the result would be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT