MATLAB Answers

solve equation whit integer output as a matrix

2 views (last 30 days)
Simon Wael Fassel
Simon Wael Fassel on 13 Feb 2020
Answered: David Goodmanson on 14 Feb 2020
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?

  0 Comments

Sign in to comment.

Answers (1)

David Goodmanson
David Goodmanson on 14 Feb 2020
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

  0 Comments

Sign in to comment.

Sign in to answer this question.