Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -106,8 +106,6 @@ def compute_low_y_curve(betas, z_a, y):
|
|
106 |
sqrt_term = np.where(sqrt_term < 0, np.nan, np.sqrt(sqrt_term))
|
107 |
|
108 |
term = (-1 + sqrt_term)/z_a
|
109 |
-
# numerator = 4* z_a * y * beta * (z_a-1) -6 * z_a * (1-y) - 12 * a**2
|
110 |
-
#denominator = (1+2*z_a)*3
|
111 |
numerator = (y - 2)*term + y * betas * ((z_a - 1)/z_a) - 1/z_a - 1
|
112 |
denominator = term**2 + term
|
113 |
# Handle division by zero and invalid values
|
@@ -129,7 +127,27 @@ def compute_high_y_curve(betas, z_a, y):
|
|
129 |
numerator = -4*a*(a-1)*y*betas - 2*a*y - 2*a*(2*a-1)
|
130 |
return numerator/denominator
|
131 |
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
if z_a <= 0 or y <= 0 or z_min >= z_max:
|
134 |
st.error("Invalid input parameters.")
|
135 |
return None
|
@@ -186,8 +204,22 @@ def generate_z_vs_beta_plot(z_a, y, z_min, z_max, beta_steps, z_steps):
|
|
186 |
)
|
187 |
)
|
188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
fig.update_layout(
|
190 |
-
title="Curves vs β: z*(β)
|
191 |
xaxis_title="β",
|
192 |
yaxis_title="Value",
|
193 |
hovermode="x unified",
|
@@ -400,9 +432,18 @@ with tab1:
|
|
400 |
beta_steps = st.slider("β steps", min_value=51, max_value=501, value=201, step=50)
|
401 |
z_steps = st.slider("z grid steps", min_value=1000, max_value=100000, value=50000, step=1000)
|
402 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
if st.button("Compute z vs. β Curves"):
|
404 |
with col2:
|
405 |
-
fig = generate_z_vs_beta_plot(z_a_1, y_1, z_min_1, z_max_1,
|
|
|
|
|
406 |
if fig is not None:
|
407 |
st.plotly_chart(fig, use_container_width=True)
|
408 |
|
@@ -410,17 +451,17 @@ with tab1:
|
|
410 |
st.markdown("""
|
411 |
**Low y Expression (Red):**
|
412 |
```
|
413 |
-
((y - 2)*(-1 + sqrt(y*β*(
|
414 |
-
((-1 + sqrt(y*β*(
|
415 |
```
|
416 |
|
417 |
**High y Expression (Green):**
|
418 |
```
|
419 |
-
(- 4
|
420 |
```
|
421 |
-
where
|
422 |
""")
|
423 |
-
|
424 |
with tab2:
|
425 |
st.header("Plot Complex Roots vs. z")
|
426 |
|
@@ -463,7 +504,7 @@ with tab3:
|
|
463 |
intersection_guesses = st.slider("Intersection search points", min_value=200, max_value=2000, value=1000, step=100)
|
464 |
intersection_tolerance = st.select_slider(
|
465 |
"Intersection tolerance",
|
466 |
-
options=[1e-6, 1e-8, 1e-10, 1e-12, 1e-14,1e-16,1e-18,1e-20],
|
467 |
value=1e-10
|
468 |
)
|
469 |
|
@@ -479,4 +520,4 @@ with tab3:
|
|
479 |
y_val = curve1(s_val, z, y_3)
|
480 |
st.write(f"Point {i+1}: s = {s_val:.6f}, y = {y_val:.6f}")
|
481 |
else:
|
482 |
-
st.write("No intersections found in the given range.")
|
|
|
106 |
sqrt_term = np.where(sqrt_term < 0, np.nan, np.sqrt(sqrt_term))
|
107 |
|
108 |
term = (-1 + sqrt_term)/z_a
|
|
|
|
|
109 |
numerator = (y - 2)*term + y * betas * ((z_a - 1)/z_a) - 1/z_a - 1
|
110 |
denominator = term**2 + term
|
111 |
# Handle division by zero and invalid values
|
|
|
127 |
numerator = -4*a*(a-1)*y*betas - 2*a*y - 2*a*(2*a-1)
|
128 |
return numerator/denominator
|
129 |
|
130 |
+
@st.cache_data
|
131 |
+
def compute_custom_expression(betas, z_a, y, num_expr_str, denom_expr_str):
|
132 |
+
"""
|
133 |
+
Compute a custom curve given numerator and denominator expressions
|
134 |
+
as strings that can depend on z_a, beta, and y.
|
135 |
+
"""
|
136 |
+
beta_sym, z_a_sym, y_sym = sp.symbols("beta z_a y", positive=True)
|
137 |
+
try:
|
138 |
+
num_expr = sp.sympify(num_expr_str)
|
139 |
+
denom_expr = sp.sympify(denom_expr_str)
|
140 |
+
except sp.SympifyError:
|
141 |
+
return np.full_like(betas, np.nan)
|
142 |
+
|
143 |
+
num_func = sp.lambdify((beta_sym, z_a_sym, y_sym), num_expr, "numpy")
|
144 |
+
denom_func = sp.lambdify((beta_sym, z_a_sym, y_sym), denom_expr, "numpy")
|
145 |
+
with np.errstate(divide='ignore', invalid='ignore'):
|
146 |
+
result = num_func(betas, z_a, y) / denom_func(betas, z_a, y)
|
147 |
+
return result
|
148 |
+
|
149 |
+
def generate_z_vs_beta_plot(z_a, y, z_min, z_max, beta_steps, z_steps,
|
150 |
+
custom_num_expr=None, custom_denom_expr=None):
|
151 |
if z_a <= 0 or y <= 0 or z_min >= z_max:
|
152 |
st.error("Invalid input parameters.")
|
153 |
return None
|
|
|
204 |
)
|
205 |
)
|
206 |
|
207 |
+
# Add custom expression if both numerator and denominator are provided
|
208 |
+
if custom_num_expr and custom_denom_expr:
|
209 |
+
custom_curve = compute_custom_expression(betas, z_a, y, custom_num_expr, custom_denom_expr)
|
210 |
+
fig.add_trace(
|
211 |
+
go.Scatter(
|
212 |
+
x=betas,
|
213 |
+
y=custom_curve,
|
214 |
+
mode="markers+lines",
|
215 |
+
name="Custom Expression",
|
216 |
+
marker=dict(size=5, color='purple'),
|
217 |
+
line=dict(color='purple'),
|
218 |
+
)
|
219 |
+
)
|
220 |
+
|
221 |
fig.update_layout(
|
222 |
+
title="Curves vs β: z*(β) Boundaries and Asymptotic Expressions",
|
223 |
xaxis_title="β",
|
224 |
yaxis_title="Value",
|
225 |
hovermode="x unified",
|
|
|
432 |
beta_steps = st.slider("β steps", min_value=51, max_value=501, value=201, step=50)
|
433 |
z_steps = st.slider("z grid steps", min_value=1000, max_value=100000, value=50000, step=1000)
|
434 |
|
435 |
+
st.subheader("Custom Expression")
|
436 |
+
st.markdown("Enter a **numerator** and a **denominator** expression as functions of `z_a`, `beta`, and `y`.")
|
437 |
+
default_num = "(y - 2)*((-1 + sqrt(y*beta*(z_a - 1)))/z_a) + y*beta*((z_a-1)/z_a) - 1/z_a - 1"
|
438 |
+
default_denom = "((-1 + sqrt(y*beta*(z_a - 1)))/z_a)**2 + ((-1 + sqrt(y*beta*(z_a - 1)))/z_a)"
|
439 |
+
custom_num_expr = st.text_input("Numerator Expression", value=default_num)
|
440 |
+
custom_denom_expr = st.text_input("Denominator Expression", value=default_denom)
|
441 |
+
|
442 |
if st.button("Compute z vs. β Curves"):
|
443 |
with col2:
|
444 |
+
fig = generate_z_vs_beta_plot(z_a_1, y_1, z_min_1, z_max_1,
|
445 |
+
beta_steps, z_steps,
|
446 |
+
custom_num_expr, custom_denom_expr)
|
447 |
if fig is not None:
|
448 |
st.plotly_chart(fig, use_container_width=True)
|
449 |
|
|
|
451 |
st.markdown("""
|
452 |
**Low y Expression (Red):**
|
453 |
```
|
454 |
+
((y - 2)*(-1 + sqrt(y*β*(z_a-1)))/z_a + y*β*((z_a-1)/z_a) - 1/z_a - 1) /
|
455 |
+
(((-1 + sqrt(y*β*(z_a-1)))/z_a)**2 + ((-1 + sqrt(y*β*(z_a-1)))/z_a))
|
456 |
```
|
457 |
|
458 |
**High y Expression (Green):**
|
459 |
```
|
460 |
+
(- 4 z_a*(z_a-1)*y*β - 2z_a*y + 2z_a*(2z_a-1))/(1-2z_a)
|
461 |
```
|
462 |
+
where z_a is the input parameter.
|
463 |
""")
|
464 |
+
|
465 |
with tab2:
|
466 |
st.header("Plot Complex Roots vs. z")
|
467 |
|
|
|
504 |
intersection_guesses = st.slider("Intersection search points", min_value=200, max_value=2000, value=1000, step=100)
|
505 |
intersection_tolerance = st.select_slider(
|
506 |
"Intersection tolerance",
|
507 |
+
options=[1e-6, 1e-8, 1e-10, 1e-12, 1e-14, 1e-16, 1e-18, 1e-20],
|
508 |
value=1e-10
|
509 |
)
|
510 |
|
|
|
520 |
y_val = curve1(s_val, z, y_3)
|
521 |
st.write(f"Point {i+1}: s = {s_val:.6f}, y = {y_val:.6f}")
|
522 |
else:
|
523 |
+
st.write("No intersections found in the given range.")
|