Vectors/rational numbers
Ältere Kommentare anzeigen
function r = r_mul(a,b)
a = [a(1),a(2)];
b = [b(1),b(2)];
M = a(2)*b(2); %finding common denominator
N = times(a,b); %multiplying the two fractions
C = gcd(N,M); %cancelling common factor
X = N./C; %simplifying fraction
Y = M./C; %simplifying fraction
r = [X,Y]; %final answer
end
I have this script file here. Adding the values of a(1),a(2),b(1),b(2) in the command window then running the function gives me a four-component vector with two 1's but I only need the other values how do I get rid of the 1's??:
a(1)=5040, a(2)=17
b(1)=22, b(2)=342920
>> r_mul(a,b)
ans =
2772 1 145741 1
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!