Question

Write a function called mysum that sums the first n positive numbers. Give the result x1...

Write a function called mysum that sums the first n positive numbers. Give the result x1 for n=20,and the result x2 for n=100.

Matlab code

Homework Answers

Answer #1

Always save function file using function name

Here given code is save by mysum.m

code of function

function sum = mysum(n)
   
    if(n>0)
        sum=0;
        for i=1:n
            sum=sum+i;
        end
       
    else
        disp('not defined')
    end
       
           
end

Result

Know the answer?
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
Similar Questions
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
Write an aggregate called selectivesum that sums the values of numbers in a column, but only...
Write an aggregate called selectivesum that sums the values of numbers in a column, but only if the value is present in the table t . E.g., suppose t contains the values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Suppose that table m has a column y of type integer. Here is the table M Psuedocode for the sfunc function:The result of the query SELECT selectivesum(y) FROM m; is 7. step(x, y) if(y is in t) return...
Write a python while loop that sums all the numbers from m to n, where “m”...
Write a python while loop that sums all the numbers from m to n, where “m” and “n” are both user given values.
Question 4 MATLAB a) Write a function file called q4.m containing the following nonlinear equations. ?(?1?2...
Question 4 MATLAB a) Write a function file called q4.m containing the following nonlinear equations. ?(?1?2 ) = ?1 2 + ?2 2 − 26 ?(?1?2 ) = 3?1 2 + 25?2 2 − 100 (1 Mark) b) Use MATLAB’s FSOLVE operator to solve these equations with x1 = 2 and x2 = 2 as your starting point. How many iterations did MATLAB use to solve them? (1 Mark)
Use C code please! Write the function definition for a function called FindQuo that takes one...
Use C code please! Write the function definition for a function called FindQuo that takes one argument of type double (arg1 ) and returns a double.  The purpose of the function is to calculate the quotient of arg1 divided by a double (num) that will be entered by the user. Inside the function declare ask and get a double value from the user called num Use a loop (while or do/while) to ensure that the user does not enter a 0.0....
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max. Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000 Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002
write a function that returns the value of the binomial expansion for a positive (or zero)...
write a function that returns the value of the binomial expansion for a positive (or zero) integer power n and any valid value of x. first write a function that calculates the value of the rth term. This all has to be done without importing any packages in python. Current code, def binomial_term_L1(x,n): return (1+x)**n but having trouble getting the code for the rth term to work.
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its...
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its sole input. If the assumption is wrong, the function returns an empty matrix. Otherwise, the function doubles every odd element of A and returns the resulting matrix. Notice that the output matrix will have all even elements. For example, the call B = matrix_problem([1 4; 5 2; 3 1], will make B equal to [2 4; 10 2; 6 2]. The function should work...
Consider the sequence(an)n≥1that starts1,3,5,7,9,...(i.e, the odd numbers in order). (a) Give a recursive definition and closed...
Consider the sequence(an)n≥1that starts1,3,5,7,9,...(i.e, the odd numbers in order). (a) Give a recursive definition and closed formula for the sequence. (b) Write out the sequence(bn)n≥2 of partial sums of (an). Write down the recursive definition for (bn) and guess at the closed formula. (b) How did you get the partial sums?
In R- Studio : Write a function that takes as an input a positive integer and...
In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT