Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Write a MATLAB function, called mysum that inputs the integer n and outputs the sum of the first n positive integers. If a negative n

Write a MATLAB function, called mysum that inputs the integer n and outputs the sum of the first n positive integers. If a negative n is input, make sure to output the value -1 and print the following statement to the user: cannot input a negative number. Use a for loop to compute the sum - dont use MATLABs built in summation function. Your function should have a header that looks like:

function y=mysum(n)

where n is the number you stop the sum at and y is the returned sum. Hint: You can check your code in MATLAB (NOT MATLAB GRADER) by typing the following into the command line: myresult = mysum(3) and check that myresult is equivalent to 1+2+3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students explore these related Databases questions