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

 採用された回答

Stephan
Stephan 2019 年 3 月 26 日

0 投票

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by