Question

No loops can be used and must only use functions that are built into matlab, aka...

No loops can be used and must only use functions that are built into matlab, aka no toolboxes

FACTORS All Factors of an Integer

FACTORS(N) returns all the factors of the positive integer N.

For example:

FACTORS(60) returns the 2 X 6 array

[ 1 2 3 4 5 6

60 30 20 15 12 10]

FACTORS(25) returns the 2 X 2 array [ 1 5

25 5]

FACTORS(7) returns the 2 X 1 array [1

7]

If N is an empty array, an empty array is returned. If N is NaN, NaN is  returned.

If N is missing or not a real, positive, numeric, integer-valued scalar

having value less than flintmax, an error string is returned by the

function error that states what is wrong with the input argument.

No For or While loops permitted.

No extraneous output to the Command Window.

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

Hello,
Please find the answer attached as under. Please give a thumbs up rating if you find the answer useful! Have a rocking day ahead!

************ MATLAB function file ***********

function f = factors(N)
if (N==[])
f=[];
elseif(N==NaN)
f=NaN;
elseif(nargin==0)
fprintf('No argumenst supplied!\n');
elseif(N<0 || floor(N)~=N)
fprintf('The supplied number is not in specified format\n');
else
K=1:N;
f = K(rem(N,K)==0);
end
end

**************** End of code ************

sample output

>> factors(7)

ans =

1 7

>> factors(0.7)
The supplied number is not in specified format>>
>>

****************************************************

PS: Please do not forget the thumbs up!

Add a comment
Know the answer?
Add Answer to:
No loops can be used and must only use functions that are built into matlab, aka...
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
  • Using Java, create functions that return specific values listed below. MUST use integer only, functions, loops,...

    Using Java, create functions that return specific values listed below. MUST use integer only, functions, loops, conditionals. Money has to be stored as two different integers, one integer for dollars and another for cents. No use of double : String moneyToString(int d, int c); // Returns the Money as words. Ex, moneyToString(10,24) => "$10.24" int biggestMoney(int d1, int c1, int d2, int c2, int d3, int c3); // Returns which money is biggest. Ex, biggestMoney(10,24,3,90,1,23) => 1 Ex, biggestMoney(3,90,1,23,10,24) =>...

  • PLEASE USE F# PROGRAMMING LANGUAGE: NO LOOPS OR CORE LIBRARY FUNCTIONS. ONLY USE RECURSION. Problem 3...

    PLEASE USE F# PROGRAMMING LANGUAGE: NO LOOPS OR CORE LIBRARY FUNCTIONS. ONLY USE RECURSION. Problem 3 (10 pts) Define a function rev that takes a list xs and returns it in the reverse order. • F# standard library has List.rev, do not use it. You need to reimplement it. In [ ]: let rev (xs: 'a list) In [ ]: // Test you function List.rev [] = rev [] |> printfn "%" List.rev [1..9] = rev [1..9] |> printfn "%b'...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • Using Java, create functions that return specific values listed below. MUST use integer only, functions, loops,...

    Using Java, create functions that return specific values listed below. MUST use integer only, functions, loops, conditionals. Money has to be stored as two different integers, one integer for dollars and another for cents. No use of double : String moneyToString(int d, int c); // Returns the Money as words. Ex, moneyToString(10,24) => "$10.24" void printSum(int d1, int c1, int d2, int c2); // Prints the sum of monies. Ex, printSum(10,24,3,90) => print "$14.14" int biggestMoney(int d1, int c1, int...

  • Matlab Question: Important! Read: No for or while loops may be used; must use the disp...

    Matlab Question: Important! Read: No for or while loops may be used; must use the disp function The top speeds of sportscars, given in miles per hour, are: 155 mph BMW M5 217 mph Lamborghini Aventador Spyder 205 mph Ferrari 488 205 mph Nissan GTR 197 mph Chevrolet Corvette Stingray ZR1 258 mph Bugatti Veyron Supersport 195 mph Dodge Viper 270 mph Hennessey Venom 155 mph BMW M3 195 mph Mercedes SL Write a function selectCars to identify cars with...

  • write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative...

    write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative integer  n and a character  c and return a String consisting of n identical characters that are all equal to c. Write a method  named  printTriangle that receives two integer  parameters  n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...

  • Please code in MatLab or Octave Output should match Sample Output in the second picture Thank...

    Please code in MatLab or Octave Output should match Sample Output in the second picture Thank You 4. In this problem we will investigate using loops to calculate the product of two matrices. Given an mxn matrix A and an n x p matrix B, the matrix product C = AB is the m xp matrix with Cij = R=1 Qikbky. Write a program which calls a function get matrix.dimensions which should • print a description of the purpose of...

  • CODE THE FOLLOWING FUNCTIONS IN JAVASCRIPT (USE OF THE ABOVE MENTIONED IN BUILT FUNCTIONS IS NOT...

    CODE THE FOLLOWING FUNCTIONS IN JAVASCRIPT (USE OF THE ABOVE MENTIONED IN BUILT FUNCTIONS IS NOT ALLOWED) Write a function that accepts an array as argument. The function should loop through the array elements and accumulate the sum of ASCII value of each character in element and return the total. For example: function([‘A’, ‘bc’, 12]); // returns 361 which is the sum of 65 + 98 + 99 + 49 + 50 Write a function that accepts two arguments (a...

  • MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS....

    MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS. THE PROGRAM TO BE MODIFIED IS THE NEXT ONE: clc clear % Approximate the value of e ^ x using the Taylor Series x = input( 'Enter the value of x for e^x. x = ' ); t = input( 'Enter the amount of desired terms. t = ' ); i = 1; e_taylor = 0; % initializing the variable for the accumulator while...

  • photo of the code please and an explnation if possible, Construct a simple MATLAB function program...

    photo of the code please and an explnation if possible, Construct a simple MATLAB function program my_factorial which calculates product of first n positive integer numbers (i.e. find factorial n!). For full points: - Make sure you protect the code from illogical use (n must be positive integer) - Test the function by comparing with built in MATLAB function factorial(n) - Make sure you test your function for any limitations. O marks) -3. Using my factorial function from the previous...

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