Question

Write a matlab m. file using loops to find the first factorial that is larger than...

Write a matlab m. file using loops to find the first factorial that is larger than an input number

Homework Answers

Answer #1

%Copy the code below-

%--------------------------------------------------------------------------------------------------------------------------------
prompt = 'input a number';

num = input(prompt); % Input command for number

prod =1; % defining product variable

for i = 1:num+1 % initiating the loop

prod = prod*i;

if prod>num % comparing value of the product with the input number

break;

end

end

fprintf('%i! ', i) % printing the required value of factorial

%---------------------------------------------------------------------------------------------

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 MATLAB program to determine the factorial value of an input integer between 1 and...
Write a MATLAB program to determine the factorial value of an input integer between 1 and 30. You may NOT use the built-in factorial function. You must implement it using a for loop. Display the result back to the user with 2 decimal places (yes, 2 decimal places). The result should follow the following format:   The factorial value is *.xx
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is...
using matlab: Q)using nested for loops to generate a 3*3 matrix where the element value is equal to the sum of its row and column number, except for the diagonal elements which are zeros
Write a program on C++ to calculate and print the factorial of a number using a...
Write a program on C++ to calculate and print the factorial of a number using a for loop. The factorial of a number is the product of all integers up to and including that number, so the factorial of 4 is 4*3*2*1= 24.
Please use MATLAB to solve it. Develop, debug, and test your own M-file to multiply two...
Please use MATLAB to solve it. Develop, debug, and test your own M-file to multiply two matrices—that is, [X ] = [Y ][Z], where [Y] is m by n and [Z] is n by p. Employ for...end loops to implement the multiplication and include error traps to flag bad cases.
IN MATLAB: Write a function file that takes a vector as an input and returns another...
IN MATLAB: Write a function file that takes a vector as an input and returns another vector with all repeated elements of the original vector. For example, the vector [3 4 1 0 4 -5 7 3] would return the vector [3 4]. Do not use the built-in function "repelem."
Write a MATLAB while-loop code that asks a user to enter an integer number until its...
Write a MATLAB while-loop code that asks a user to enter an integer number until its factorial is smaller than 100.
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)
A = [-1000:1:1000] write a script file that gives the positive numbers greater than 480 and...
A = [-1000:1:1000] write a script file that gives the positive numbers greater than 480 and divisible by 3. Hint: Use this command if A(i)>480&&(rem(A(i),3)==0) and indeed, if is always accompanied by an end Note: Using Matlab
MATLAB: Do the following with the provided .m file (a) In the .m file, we have...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have provided three questions. Make sure to answer them. (b) Now on the MATLAB prompt, let us create any two 3 × 3 matrices and you can do the following: X=magic(3); Y=magic(3); X*Y matrixMultiplication3by3(X,Y) (c) Now write a new function in MATLAB called matrixMultiplication that can multiply any two n × n matrix. You can safely assume that we will not test your program with...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have...
MATLAB: Do the following with the provided .m file (a) In the .m file, we have provided three questions. Make sure to answer them. (b) Now on the MATLAB prompt, let us create any two 3 × 3 matrices and you can do the following: X=magic(3); Y=magic(3); X*Y matrixMultiplication3by3(X,Y) (c) Now write a new function in MATLAB called matrixMultiplication that can multiply any two n × n matrix. You can safely assume that we will not test your program with...