Find the variable inside the LCM argument
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I came up with a B=lcm(nrt,Nr*Nc) formula how to find Nr*Nc ?? i have B and nrt
0 Kommentare
Antworten (3)
John D'Errico
am 22 Apr. 2024
Bearbeitet: John D'Errico
am 22 Apr. 2024
You have the expression:
B=lcm(nrt,Nr*Nc)
where the variables B and nrt are known. The unknown variable is the product nr*nt. I'll call that product X, since it is the unknown. The solution is actually quite simple.
X = divisors(nrt)*B/nrt
Here the divisors function is part of the symbolic toolbox. This formula requires only that the ratio B/nrt is a whole number.
help sym/divisors
I'll explain it below. The LCM function is a pretty simple one. It finds the least common multiple of two numbers.
B = lcm(nrt,X)
For example, what is the least common multiple of the pair (3,5)? Since 3 and 5 share no common prime divisors, then the least common multiple is just 15. That is, the least common multiple is the smallest integer that has both of the elements as factors.
lcm(3,5)
When the two numbers have common divisors, then the LCM is not quite as large as their product. For example, with 6 and 10, they both share a common prime factor of 2. So the lcm is not as large as 60. Instead, it is 30.
lcm(6,10)
This might point out an issue. The solution X for the problem you show, has X as NOT being a unique number. FOR EXAMPLE, it is true that both of these results yield the LCM:
lcm(60,42)
lcm(60,7)
Do you see that solving for X in your problem does not have a unique solution? Hmm. So, what can we do? We can solve for all possible solutions. The solution could employ the divisors function, part of the symbolic toolbox. For example, given B. Here, I'll choose B=300. If B is the LCM of two numbers, then it must be true that B is a multiple of nrt. Remember LCM stands for Least Common MULTIPLE.
B = 300;
nrt = 12;
Then the simple formula to compute ALL possible solutions for X (X is the product in your problem, so X=nr*nt) is just:
X = divisors(nrt)*B/nrt
Test it out.
lcm(nrt,X)
In each case, you see the LCM is 300.
Again, think about it. If B=lcm(nrt,X), then B MUST be a multiple of nrt. Surely you agree with that? But what is the other term? After we cancel out the factors of B that appear in nrt, then what remains would be any of the divisors of nrt.
This also points out that your problem will not have a solution all of the time. For example:
B = 12345; factor(B)
nrt = 35; factor(nrt)
A solution exists ONLY if nrt divides B evenly, so B must be a multiple of nrt. Here we would have
B/nrt
which fails the requirement.
Hmm. I don't like how I explained this.
0 Kommentare
Hassaan
am 22 Apr. 2024
Bearbeitet: Hassaan
am 22 Apr. 2024
% Known values of B and nrt
B = 120; % Example value for B
nrt = 8; % Example value for nrt
% Find all divisors of B
divisorsB = divisors(B);
% Array to hold possible values of Nr*Nc
possible_NrNc = [];
% Check each divisor to see if it's a valid Nr*Nc
for i = 1:length(divisorsB)
candidate = divisorsB(i);
if lcm(nrt, candidate) == B
possible_NrNc = [possible_NrNc, candidate];
end
end
% Display the possible values for Nr*Nc
disp('Possible values for Nr*Nc are:');
disp(possible_NrNc);
function divs = divisors(n)
divs = [];
for i = 1:n
if mod(n, i) == 0
divs = [divs, i];
end
end
end
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
1 Kommentar
John D'Errico
am 22 Apr. 2024
Note that divisors already exsits in MATLAB. It is part of the symbolic toolbox. And there is a simple direct solution for the problem.
sai charan sampara
am 22 Apr. 2024
Hi ali,
If the LCM (least common multiple) of 2 numbers is known and one of the number is known then the value of the second number is not always unique. We know that product of two numbers is equal to the product of their LCM and GCD (greatest common divisor). So the second number is given by LCM multiplied by GCD divided by the first number. In this case LCM and the first number is known.
There are two possible cases. First case is when the value of LCM divided by the first number and the first number do not have a common factor. In this case the GCD can range from 1 to first number's value, comprising of all the factors of first number in between. So the possible values for the second number in that case are LCM multiplied any factor of the first number divided by the first number. Here is an example code demonstrating case 1:
B=168; %LCM
nrt=24; % 1st Number
factors_of_nrt=[1,2,3,4,6,8,12,24]; % Factors of the first number
N=B*factors_of_nrt/nrt % initial estimated values of the second number
N_true=0; % trivial solution
j=0;
for i =1:length(factors_of_nrt)
if(lcm(N(i),nrt)==B)
j=j+1;
N_true(j)=N(i);
end
end
N_true % All possible values for Nc*Nr as follows
In second case if the value of LCM divided by first number and the first number have a common factor. In this case all the values obtained in the above method will not satisfy the above condition. Here is the example code for case 2:
B=1152; %LCM
nrt=24; % 1st Number
factors_of_nrt=[1,2,3,4,6,8,12,24]; % Factors of the first number
N=B*factors_of_nrt/nrt % initial estimated values of the second number
N_true=0; % trivial solution
j=0;
for i =1:length(factors_of_nrt)
if(lcm(N(i),nrt)==B)
j=j+1;
N_true(j)=N(i);
end
end
N_true % All possible values for Nc*Nr as follows
Hence the solution is not always unique. The trivial solution that always works is for "Nc*Nr" to be equal to "B" itself. The other possible solutions depend upon the values of the first number and LCM divided by first number.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Linear Model Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!