Write a MATLAB function file that finds the greatest common

Write a MATLAB function file that finds the greatest common divisor of two integers. Your function definition line is given as follows: function gcd=find_gcd (a, b) where your input variables are integers a and b and your output argument is the returned result gcd. Test your function under the command window to find the gcd of 129 and 15.

Solution

First write the following command in m-file.

function f=find_gcd(a,b)

f=gcd(a,b)

end

Now save as find_gcd.m now type the following command in command prompt;

>> a=129;
>> b=15;
>> find_gcd(a,b)

THE ANSWER IS,

f =

     3


ans =

     3

 Write a MATLAB function file that finds the greatest common divisor of two integers. Your function definition line is given as follows: function gcd=find_gcd (

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site