def poly_div(): """Calcula a divisao de dois polinomios.""" poly_1 = request.form['name'] poly_2 = request.form['email'] poly_array_1 = string_to_poly_array(poly_1) poly_array_2 = string_to_poly_array(poly_2) poly_result = [0] * ((len(poly_array_1)-1) - (len(poly_array_2)-1) + 1) poly_actual = poly_array_1 while len(poly_actual) >= len(poly_array_2): if len(poly_actual) == 1 and poly_actual[0] == 0: break aux = [0] * ((len(poly_array_1)-1) - (len(poly_array_2)-1) + 1) dividendo = poly_actual[-1] divisor = poly_array_2[-1] aux[(len(poly_actual) - 1) - (len(poly_array_2) - 1)] = dividendo // divisor poly_result[(len(poly_actual) - 1) - (len(poly_array_2) - 1)] = dividendo // divisor poly_actual2 = poly_mult_aux(aux, poly_array_2) poly_actual = poly_sub_aux(poly_actual, poly_actual2) if len(poly_actual) == 0: break else: while poly_actual[-1] == 0 and len(poly_actual) > 1: poly_actual.pop() return jsonify({'name' : poly_array_to_string(poly_result)})
def poly_mult(): """Calcula a multiplicacao de dois polinomios.""" poly_1 = request.form['name'] poly_2 = request.form['email'] poly_array_1 = string_to_poly_array(poly_1) poly_array_2 = string_to_poly_array(poly_2) poly_result = [0] * ((len(poly_array_1)-1) + (len(poly_array_2)-1) + 1) for i in range(0, len(poly_array_1)): for j in range(0, len(poly_array_2)): poly_result[i+j] += poly_array_1[i] * poly_array_2[j] return jsonify({'name' : poly_array_to_string(poly_result)})
def poly_sub(): """Calcula a subtracao de dois polinomios.""" poly_1 = request.form['name'] poly_2 = request.form['email'] poly_array_1 = string_to_poly_array(poly_1) poly_array_2 = string_to_poly_array(poly_2) if(len(poly_array_1) > len(poly_array_2)): poly_result = [0] * len(poly_array_1) while(len(poly_array_2) < len(poly_array_1)): poly_array_2.append(0) else : poly_result = [0] * len(poly_array_2) while(len(poly_array_1) < len(poly_array_2)): poly_array_1.append(0) for i in range(0, len(poly_result)): poly_result[i] = poly_array_1[i] - poly_array_2[i] return jsonify({'name' : poly_array_to_string(poly_result)})
def create_plot_with_roots(feature, pipeline): roots = pipeline[5] x0_list = pipeline[4] derivate_array = pipeline[3] alpha = pipeline[2] descartes_matrix = pipeline[1] complex_bool = pipeline[0] points = [] for i in range(0, len(roots)): points.append((round(roots[i]), poly_evaluate(feature, round(roots[i])))) print(points) x = [x[0] for x in points] y = [x[1] for x in points] p1 = feature valores = [i for i in range(-100,100)] p1_valuete = poly_evaluate_list(p1, valores) fig = go.Figure( data=[ go.Scatter( x= valores, y= p1_valuete, mode='lines', line=dict(color='#673ab7'), name='Polinomio' ), go.Scatter( x=x, y=y, mode='markers', name='Raizes', marker=dict( size=12, color='#673ab7' ) ) ], layout=go.Layout( plot_bgcolor='rgba(0,0,0,0)', xaxis=dict( autorange=True, showgrid=True, zeroline=True, showline=False, ticks='', showticklabels=True, zerolinewidth=1, zerolinecolor='#333', gridcolor='#d3d3d3', gridwidth=1 ), yaxis=dict( autorange=True, showgrid=True, zeroline=True, showline=True, ticks='', showticklabels=True, zerolinewidth=1, zerolinecolor='#333', gridcolor='#d3d3d3', gridwidth=1 ), annotations=[ go.layout.Annotation( text="Teste de raizes complexas: "+str(complex_bool)+"<br>"+"Descartes: "+str(descartes_matrix)+"<br>"+"Fujiwara: "+str(alpha)+"<br>"+"Derivada: "+poly_array_to_string(derivate_array)+"<br>"+"Separação das Raízes: "+str(x0_list)+"<br>", align='left', showarrow=False, xref='paper', yref='paper', x=0.0, y=1.4 #bordercolor='#673ab7', #borderwidth=1 ) ] ) ) graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder) return graphJSON