-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgera_pol.sh
More file actions
executable file
·38 lines (36 loc) · 838 Bytes
/
gera_pol.sh
File metadata and controls
executable file
·38 lines (36 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
echo "Digite o grau do polinômio"
read POT
POT_ORG=$POT
while [[ $POT -ge 0 ]]; do
COEF=$(seq -1000 1000 | shuf -n 1)
COEF_DER=$[ $COEF * $POT ]
POT_DER=$[ $POT - 1 ]
if [[ ( $POT -eq 0 ) && ( $COEF -gt 0 ) ]]; then
POL="${POL} + $COEF"
DER="${DER}"
elif [[ ( $POT -eq 0 ) && ( $COEF -lt 0 ) ]]; then
POL="${POL} ${COEF}"
DER="${DER}"
elif [[ ( $COEF -gt 0 ) && ( $POL != "" ) ]]; then
POL="${POL} + ${COEF}x^${POT}"
if [[ $POT_DER -eq 0 ]]; then
DER="${DER} + ${COEF_DER}"
else
DER="${DER} + ${COEF_DER}x^${POT_DER}"
fi
elif [[ $COEF -eq 0 ]]; then
POL="${POL}"
DER="${DER}"
else
POL="${POL} ${COEF}x^${POT}"
if [[ $POT_DER -eq 0 ]]; then
DER="${DER} ${COEF}"
else
DER="${DER} ${COEF_DER}x^${POT_DER}"
fi
fi
POT=$[ $POT - 1 ]
done
echo "f(x) =${POL}"
echo "f'(x) =${DER}"