solve equation whit integer output as a matrix

3 ビュー (過去 30 日間)
Simon Wael Fassel
Simon Wael Fassel 2020 年 2 月 13 日
回答済み: David Goodmanson 2020 年 2 月 14 日
Hey I'm trying to solve af gearratio problem.
I want at gearratio of u = 3.9 , whit toothnumers z1 and z2 in relation as z2/z1 = u.
z1 and z2 ar of couse integers, whit a minimum of 17.
Also z1 < z2.
Now I want to solve z2/z1 = u and get the pairs of z1 and z2 thaqt follows this.
syms z1 z2
assume( in(z1,'integer') & z1 >= 17 & z1 > 100);
assume( in(z2,'integer') & z2 >= 17 & z2 > 100);
assumeAlso( z1 < z2);
u = 3.9;
eq = z2/z1 == u;
[z1Sol z2Sol] = solve( eq, [z1 z2])
u = vpa(z2Sol/z1Sol)
but I only get one set of values for z1 and z2, and they are not even the smallest values possible.
Hor can I get Matlab to return af matrix of values that follows my rules?

回答 (1 件)

David Goodmanson
David Goodmanson 2020 年 2 月 14 日
Hi Simon,
you have
z2/z1 = 3.9
% or
10*z2 = 39*z1
since 10 and 39 are relatively prime, i.e. they have no prime factors in common, the only possible solutions are
z1 = 10*m
z2 = 39*m
for any integer m. So:
m = (1:20)'
z1 = 10*m;
z2 = 39*m;
z1z2 = [z1 z2] % display
which includes the version found by 'solve'. Your restrictions appear to not be quite right since with z1 >= 17 & z1 > 100, you don't need z1<= 17. However, suppose you want, say, z2<200. Then
ind = z2 < 200;
z1new = z1(ind);
z2new = z2(ind);
z1z2new = [z1new z2new] % display

カテゴリ

Help Center および File ExchangeMathematics and Optimization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by