Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB: Most teachers of mathematics will tell you that is is important to have

ID: 3840488 • Letter: M

Question

MATLAB: Most teachers of mathematics will tell you that is is important to have a strong understanding of
fractional mathematics. However, computers work with floating point number and not really with
fractions. For example 1/2 is entered as 0.5 even if the user were to type 1/2 as the input line would
do the math here.
Design a detailed pseudo code algorithm to as the user for 4 numbers representing two fractions.
For notation let the fractions be represented as
numerator1/denominator1 and denominator2/numerator2
Write a script which in order calculates and then clearly displays the sum, difference product and
division of the first fraction with the second fraction. By hand execute your algorithm with the
fractions 1/6 and 2/5 to create your test output. Note that you do have have to attempt to program
any fraction reduction.

Most teachers of mathematics will tell you that is is important to have a strong understanding of fractional mathematics. However, computers work with floating point number and not really with fractions. For example 1/2 is entered as 0.5 even if the user were to type 1/2 as the input line would do the math here. Design a detailed pseudo code algorithm to as the user for 4 numbers representing two fractions. For notation let the fractions be represented as numeratorl numerator 2 and denominator 2 denominator Write a script which in order calculates and then clearly displays the sum, difference product and division of the first fraction with the second fraction. By hand execute your algorithm with the fractions 1/6 and 2/5 to create your test output. Note that you do have have to attempt to program any fraction reduction.

Explanation / Answer

function fraction(n1, d1, n2, d2)
    din = lcm(d1,d2); %indicates dinominator
    num = n1 * din/d1 + n2 * din/d2; %indicats numerator
    fac = gcd(num , din); %finds fators and recues it to minimal form
    sum = [num/fac ; din/fac] %sum representation
    %notations are same for all
    num = n1 * din/d1 - n2 * din/d2;
    fac = gcd(num , din);
    diff = [num/fac ; din/fac]
  
    din = d1*d2;
    num = n1*n2;
    fac = gcd(num , din);
    mult = [num/fac ; din/fac]
  
    din = d1*n2;
    num = n1*d2;
    fac = gcd(num , din);
    div = [num/fac ; din/fac]
end

fraction(1, 2, 1, 4)