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

 Réponse acceptée

Stephan
Stephan le 26 Mar 2019

0 votes

a(1)=5040;
a(2)=17;
b(1)=22;
b(2)=342920;
res = r_mul(a,b)
function r = r_mul(a,b)
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(1),Y(1)]; %final answer
end

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by