def nlers2(qL, qR, xvect): aL = eigenvalue(qL) aR = eigenvalue(qR) xvect = toarray(xvect) if(aL > aR): # is a Shock wave s = ( flux(qR) - flux(qL) ) / ( qR - qL ) solution = shock(xvect, s, qL, qR) else: # is a Rarefaction solution, rarefactionlist = rarefaction(xvect, aL, aR, qL, qR) for rarefact in rarefactionlist: solution[rarefact] = newton( 0.5 * ( qL + qR ), xvect[rarefact] ) return solution
def nlers(qL, qR, xi): """ function q = NLERS(qL,qR,xi) aL = eigenvalue(qL); aR = eigenvalue(qR); eta=0.001; if(aL > aR) % Shock wave s = (flux(qR)-flux(qL))/(qR-qL); if(xi<=s) q = qL; else q = qR; end else % Rarefaction if(xi<aL) q = qL; elseif(xi>aR) q = qR; else q=0.5*(qL+qR); q = Newton(q,xi); end end """ aL = eigenvalue(qL); aR = eigenvalue(qR); if aL > aR: # is a Shock wave s = ( flux(qR) - flux(qL) ) / ( qR - qL ); if (xi <= s): q = qL; else: q = qR; else: # is a Rarefaction if xi < aL: q = qL elif xi > aR: q = qR else: #print( 'is a Rarefaction') #import pdb; pdb.set_trace() q = 0.5 * (qL + qR) q = newton(q, xi) return q
# Plotting rough interval estimate plt.plot(-r(COEFF), 0, color='r', marker='>', markersize=7) plt.plot(r(COEFF), 0, color='r', marker='<', markersize=7) # Plotting accurate interval estimate plt.plot(acc_lower(COEFF), 0, color='g', marker='>', markersize=5) plt.plot(acc_upper(COEFF), 0, color='g', marker='<', markersize=5) x1 = np.arange(x_from, x_to, 0.01) y1 = f(x1) plt.plot(x1, y1) intervals = solve.get_all_intervals(f, acc_lower(COEFF), acc_upper(COEFF), 0.1) for i, interval in enumerate(intervals): cor, it_cor = solve.chord(f, interval[0], interval[1]) ntn, it_ntn = solve.newton(f, f_prime, interval[0]) scn, it_scn = solve.scan(f, interval[0], interval[1]) print('----- f(x) root #{} -----'.format(i + 1)) print('Chord = ', cor, ' iterations = ', it_cor) print('Newton = ', ntn, ' iterations = ', it_ntn) print('Scan = ', scn, ' iterations = ', it_scn) print() plt.plot(ntn, 0, 'ro') print('f(x) np.roots = {}'.format(np.roots(COEFF)), end='\n\n\n') # ---- Plotting g(x) ---- # plt.figure(1) plt.title('Function g(x)')