reuse lint, modificació de ng-flask per fer-ho mitjanament d'alt nivell
[exercicis-automatics-matematiques.git] / equacions-segon-grau-senzilles.conTeXt.erb
blobe560656e9cf66639074acdd998d231d5a56c485b
1 \environment entorn
3 \starttext
5 \startsubject[title={Equacions de segon grau senzilles}]
7 \startsubsubject[title={Preguntes}]
9 <%
11 exercicis = Hash.new
15 <%# Exercici 1 %>
17 exercicis[1] = Array.new
19 for i in (1...3)
20   parametres = Hash.new
21   parametres['a'] = rand(-10..10)
22   parametres['b'] = rand(-10..10)
23   parametres['c'] = rand(-10..20)
24   if parametres['a'] == 0
25     parametres['a'] = 1
26   end
27   if parametres['b'] == 0
28     parametres['b'] = 1
29   end
30   if parametres['c'] == 0
31     parametres['c'] = 1
32   end
33   
34   exercicis[1].push(parametres)
35 end
38 \startexercici[reference=exercici-1] Resoleu les equacions:
39 \startitemize[a]
40 <% exercicis[1].each do |par| %>
41 \item
42 <% if par['b'] > 0 and par['c'] > 0 %>
43 $<%=par['a']%>x^2 + <%=par['b']%>x + <%=par['c']%> = 0$
44 <% end %>
45 <% if par['b'] > 0 and par['c'] < 0 %>
46 $<%=par['a']%>x^2 + <%=par['b']%>x  <%=par['c']%> = 0$
47 <% end %>
48 <% if par['b'] < 0 and par['c'] > 0 %>
49 $<%=par['a']%>x^2  <%=par['b']%>x + <%=par['c']%> = 0$
50 <% end %>
51 <% if par['b'] < 0 and par['c'] < 0 %>
52 $<%=par['a']%>x^2  <%=par['b']%>x  <%=par['c']%> = 0$
53 <% end %>
54 <% end %>
55 \stopitemize
56 \stopexercici
60 <%# Exercici 2 %>
62 exercicis[2] = Array.new
64 for i in (1...3)
65   parametres = Hash.new
66   
67   parametres['a'] = rand(-20..20)
68   parametres['b'] = rand(1..30)
69   parametres['c'] = rand(1..30)
70   parametres['d'] = rand(-20..20)
72   if parametres['a'] + parametres['b'] == 0
73     parametres['a'] = parametres['b'] + 1
74   end
75   
76   exercicis[2].push(parametres)
77 end
81 \startexercici[reference=exercici-2] Resoleu les equacions següents:
82 \startitemize[a]
83 <% exercicis[2].each do |par| %>
84 \item $<%=par['a']%>x^2 + <%=par['b']%> - <%=par['c']%>x = <%=par['d']%> -<%=par['b']%>x^2 $
85 <% end %>
86 \stopitemize
87 \stopexercici
91 <%# Exercici 3 %>
93 exercicis[3] = Array.new
95 for i in (1...3)
96   parametres = Hash.new
97   
98   parametres['a'] = rand(-10..10)
99   if parametres['a'] == 0
100     parametres['a'] = 1
101   end  
102   parametres['b'] = rand(1..10)
103   
104   exercicis[3].push(parametres)
109 \startexercici[reference=exercici-3] Resoleu les equacions següents:
110 \startitemize[a]
111 <% exercicis[3].each do |par| %>
112 \item <% if par['a'] < 0 %>
113 $(x+<%=par['a'].abs %>)^2 = <%=par['b']%>$
114 <% else %>
115 $(x-<%=par['a']%>)^2 = <%=par['b']%>$
116 <% end %>
117 <% end %>
118 \stopitemize
119 \stopexercici
121 <%# Exercici 4 %>
123 exercicis[4] = Array.new
125 for i in (1...3)
126   parametres = Hash.new
127   
128   parametres['a'] = rand(-10..10)
129   if parametres['a'] == 0
130     parametres['a'] = 1
131   end  
132   parametres['b'] = rand(1..10)
133   parametres['c'] = rand(-10..10)
134   if parametres['c'] == 0
135     parametres['c'] = 1
136   end
137   
138   exercicis[4].push(parametres)
143 \startexercici[reference=exercici-4] Resoleu les equacions següents:
144 \startitemize[a]
145 <% exercicis[4].each do |par| %>
146 \item <% if par['a'] < 0 %>
147 $<%=par['c']%>(x+<%=par['a'].abs %>)^2 = <%=par['b']%>$
148 <% else %>
149 $<%=par['c']%>(x-<%=par['a']%>)^2 = <%=par['b']%>$
150 <% end %>
151 <% end %>
152 \stopitemize
153 \stopexercici
155 <%# Exercici 5 %>
157 exercicis[5] = Array.new
159 for i in (1...3)
160   parametres = Hash.new
161   
162   parametres['a'] = rand(-10..10)
163   if parametres['a'] == 0
164     parametres['a'] = 1
165   end  
166   parametres['b'] = rand(1..10)
167   parametres['c'] = rand(-10..10)
168   parametres['d'] = rand(-10..10)
169   
170   exercicis[5].push(parametres)
175 \startexercici[reference=exercici-5] Resoleu les equacions següents:
176 \startitemize[a]
177 <% exercicis[5].each do |par| %>
178 \item  $<%=par['a']%>(x+<%=par['b']%>)^2 <%= par['c'] > 0 ? '+' : '-' %><%=par['c'].abs %>x = <%=par['d']%>$
179 <% end %>
180 \stopitemize
181 \stopexercici
183 \stopsubsubject
185 <%# ----------------------- Solucions ------------------------ %>
186 \page[yes]
187 \startsubsubject[title={Solucions}]
189 \startitemize
190 \sym{\in[exercici-1]}
191 \startitemize[a, text]
192 <% exercicis[1].each do |par| %>
193 <% 
194    disc = par['b'].pow(2) - 4*par['a']*par['c']
196 <% if disc < 0 %>
197 \item No té solució
198 <% else %>
200   solucio_1 = Rational(Math.sqrt(disc) - par['b'],2*par['a'])
201   solucio_2 = Rational(-Math.sqrt(disc) - par['b'],2*par['a'])
203 \item $x \simeq <%=solucio_1.to_f.round(2)%>, x \simeq <%=solucio_2.to_f.round(2)%>$
204 <% end %>
205 <% end %>
206 \stopitemize
208 \sym{\in[exercici-2]}
209 \startitemize[a, text]
210 <% exercicis[2].each do |par| %>
211 <% 
212    disc = par['c']*par['c'] - 4*(par['a']+par['b'])*(par['b'] - par['d'])
214 <% if disc < 0 %>
215 \item No té solució
216 <% else %>
218   solucio_1 = Rational(Math.sqrt(disc) + par['c'],2*(par['a']+par['b']))
219   solucio_2 = Rational(-Math.sqrt(disc) + par['c'],2*(par['a']+par['b']))
221 \item $x \simeq <%=solucio_1.to_f.round(2)%>, x \simeq <%=solucio_2.to_f.round(2)%>$
222 <% end %>
223 <% end %>
224 \stopitemize
226 \sym{\in[exercici-3]}
227 \startitemize[a, text]
228 <% exercicis[3].each do |par| %>
229 <% 
230    disc = par['b']
232 <% if disc < 0 %>
233 \item No té solució
234 <% else %>
236   solucio_1 = Rational(Math.sqrt(disc) + par['a'],1)
237   solucio_2 = Rational(-Math.sqrt(disc) + par['a'],1)
239 \item $x \simeq <%=solucio_1.to_f.round(2)%>, x \simeq <%=solucio_2.to_f.round(2)%>$
240 <% end %>
241 <% end %>
242 \stopitemize
245 \sym{\in[exercici-4]}
246 \startitemize[a, text]
247 <% exercicis[4].each do |par| %>
248 <% 
249    disc = Rational(par['b'], par['c'])
251 <% if disc < 0 %>
252 \item No té solució
253 <% else %>
255   solucio_1 = Rational(Math.sqrt(disc) + par['a'],1)
256   solucio_2 = Rational(-Math.sqrt(disc) + par['a'],1)
258 \item $x \simeq <%=solucio_1.to_f.round(2)%>, x \simeq <%=solucio_2.to_f.round(2)%>$
259 <% end %>
260 <% end %>
261 \stopitemize
264 \sym{\in[exercici-5]}
265 \startitemize[a, text]
266 <% exercicis[5].each do |par| %>
267 <% 
268    disc = (2 * par['a']* par['b'] + par['c']).pow(2) - 4*par['a']*(par['a']*par['b'].pow(2) - par['d']) 
270 <% if disc < 0 %>
271 \item No té solució
272 <% else %>
274   solucio_1 = Rational(Math.sqrt(disc) - (2*par['a']*par['b'] + par['c']),2*par['a'])
275   solucio_2 = Rational(-Math.sqrt(disc) - (2*par['a']*par['b'] + par['c']),2*par['a'])
277 \item $x \simeq <%=solucio_1.to_f.round(2)%>, x \simeq <%=solucio_2.to_f.round(2)%>$
278 <% end %>
279 <% end %>
280 \stopitemize
282 \stopitemize
284 \vfill
285 Les solucions d'aquests exercicis s'han calculat automàticament usant programari lliure: encara que totes les expressions són correctes, potser algunes es poden simplificar més.
287 \stopsubsubject
289 <%# ----------------------- Resolució ------------------------ %>
290 \page[yes]
291 \startsubsubject[title={Resolució}]
293 \startitemize
294 \sym{\in[exercici-1]}
295 \startitemize[a]
296 <% exercicis[1].each do |par| %>
297 <% a = par['a']
298    b = par['b']
299    c = par['c']
300    disc = b.pow(2) - 4*a*c
303 \item $<%=a%>x^2 <%= b < 0 ? '-' : '+' %><%= b.abs %>x <%= c < 0 ? '-' : '+' %><%= c.abs %> = 0$ $\Rightarrow$ $(<%=2*a%>x <%= b < 0 ? '-' : '+' %><%= b.abs %>)^2 = <%= b < 0 ? '(' : '' %><%= b %><%= b < 0 ? ')' : '' %>^2 -4\cdot <%= a < 0 ? '(' : '' %><%= a %><%= a < 0 ? ')' : '' %>\cdot <%= c < 0 ? '(' : '' %><%= c %><%= c < 0 ? ')' : '' %>$ $\Rightarrow$ $(<%=2*a%>x <%= b < 0 ? '-' : '+' %><%= b.abs %>)^2 = <%=disc%>$ $\Rightarrow$ <% if disc <0 %> No té solució <% else %>  $<%=2*a%>x <%= b < 0 ? '-' : '+' %><%= b.abs %> = \pm \sqrt{<%=disc%>}$ $\Rightarrow$ $x \simeq <%=Rational(Math.sqrt(disc)-b,2*a).to_f.round(2) %>$,  $x \simeq <%=Rational(-Math.sqrt(disc)-b,2*a).to_f.round(2) %>$<% end %>
304 <% end %>
305 \stopitemize
307 \sym{\in[exercici-2]} \startitemize[a]
308 <% exercicis[2].each do |par| %>
309 <% a = par['a']
310    b = par['b']
311    c = par['c']
312    d = par['d']
313    disc = c.pow(2) - 4*(a+b)*(b-d)
316 \item $<%=a%>x^2 + <%=b%> - <%=c%>x = <%=d%> -<%=b%>x^2$ $\Rightarrow$ $<%=a%>x^2 + <%=b%> -<%=c%>x <%=d < 0 ? '+' : '-'%><%=d.abs%> + <%=b%>x^2 = 0$ $\Rightarrow$ $ <%=a+b%>x^2 - <%=c%>x <%=b-d < 0 ? '-' : '+'%><%=(b-d).abs%> = 0$ $\Rightarrow$ $(<%=2*(a+b)%>x - <%=c%>)^2 = <%=disc%>$ $\Rightarrow$ <% if disc <0 %> No té solució <% else %> $<%=2*(a+b)%>x - <%=c%> = \pm\sqrt{<%=disc%>}$ $\Rightarrow$ $x \simeq <%= Rational(c+Math.sqrt(disc).round(3),2*(a+b)).to_f.round(3) %>$, $x \simeq <%= Rational(c-Math.sqrt(disc).round(3),2*(a+b)).to_f.round(3) %>$ <% end %>
317 <% end %>
318 \stopitemize
320 \sym{\in[exercici-3]} \startitemize[a]
321 <% exercicis[3].each do |par| %>
322 <% a = par['a']
323    b = par['b']
326 \item $(x<%= a < 0 ? '+' : '-' %><%=par['a'].abs %>)^2 = <%=par['b']%>$ $\Rightarrow$ $x<%= a < 0 ? '+' : '-' %><%=par['a'].abs %> = \pm \sqrt{<%=par['b']%>}$ $\Rightarrow$ <% if b < 0 %>No té solució <% else %> $x = \pm\sqrt{<%=b%>}  <%= a < 0 ? '-' : '+' %><%=par['a'].abs %>$ $\Rightarrow$ $x \simeq <%=Rational(Math.sqrt(b)+a,1).to_f.round(3) %>$, $x \simeq <%=Rational(-Math.sqrt(b)+a,1).to_f.round(3) %>$ <% end %> 
327 <% end %>
328 \stopitemize
330 \sym{\in[exercici-4]} \startitemize[a]
331 <% exercicis[4].each do |par| %>
332 <% a = par['a']
333    b = par['b']
334    c = par['c']
337 \item $<%=c%>(x<%= a > 0 ? '-' : '+' %><%=a.abs %>)^2 = <%=b%>$ $\Rightarrow$ $(x <%= a > 0 ? '-' : '+' %> <%=a.abs %>)^2 = \frac{<%=b %>}{<%=c %>}$ $\Rightarrow$ <% if c < 0 %> No té solució <% else %> $x = \pm \sqrt{\frac{<%=b %>}{<%=c %>}} <%= a > 0 ? '+' : '-' %><%=a.abs %> $ $\Rightarrow$ $x \simeq <%= (Math.sqrt(Rational(b,c)) + a).round(3)%>$, $x \simeq <%= (-Math.sqrt(Rational(b,c)) + a).round(3)%>$ <% end %>
338 <% end %>
339 \stopitemize
342 \sym{\in[exercici-5]} \startitemize[a]
343 <% exercicis[5].each do |par| %>
344 <% a = par['a']
345    b = par['b']
346    c = par['c']
347    d = par['d']
348    disc = (2 * a* b + c).pow(2) - 4*a*(a*b.pow(2) - d) 
351 \item $<%=a%>(x+<%=b%>)^2 <%= c > 0 ? '+' : '-' %> <%=c.abs%>x = <%=d%>$ $\Rightarrow$ $<%=a%>(x^2 + <%=2 * b %> x  + <%=b.pow(2)%>) <%= c > 0 ? '+' : '-' %> <%=c.abs%>x = <%=d%>$ $\Rightarrow$ $<%=a%>x^2  <%= a > 0 ? '+' : '-' %><%=(2 * a* b).abs %> x  <%= a > 0 ? '+' : '-' %> <%=(a*b.pow(2)).abs%> <%= c > 0 ? '+' : '-' %> <%=c.abs%>x = <%=d%>$ $\Rightarrow$ $<%=a%>x^2 <%= 2*a*b +c > 0 ? '+' : '-' %> <%=(2 * a* b + c).abs %> x <%= a*b.pow(2) -d > 0 ? '+' : '-' %> <%= (a*b.pow(2) - d).abs%> = 0$ $\Rightarrow$ $(<%=2*a%>x <%= 2*a*b +c > 0 ? '+' : '-' %> <%=(2 * a* b + c).abs %>)^2 = <%= (2 * a* b + c).pow(2) - 4*a*(a*b.pow(2) - d) %>$ $\Rightarrow$ <% if disc < 0 %> No té solució <% else %> $x \simeq <%= Rational(Math.sqrt(disc) - (2 * a* b + c), 2*a).to_f.round(3) %>$, $x \simeq <%= Rational(-Math.sqrt(disc) - (2 * a* b + c), 2*a).to_f.round(3) %>$ <% end %>
353 <% end %>
354 \stopitemize
357 \stopitemize
359 \vfill
360 La resolució d'aquests exercicis s'ha calculat automàticament usant programari lliure: encara que totes les expressions són correctes, potser algunes es poden simplificar més.
362 \stopsubsubject
364 \stopsubject
366 \stoptext