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

 采纳的回答

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 Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by