Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substitute should be able of replacing an expression with a variable #989

Open
ufechner7 opened this issue Oct 6, 2023 · 2 comments
Open

Comments

@ufechner7
Copy link

ufechner7 commented Oct 6, 2023

The following code does not work:

# replace an expression with a variable
using Symbolics

@variables t
@syms ω(t) Pg(t) Pge(t) Pgc(t)
@variables A R a b Γ ρ U J Q

expr = (0.5A*R*a*Γ*ρ*(U^2)) / (J*ω(t)) - J*((0.5A*Γ*ρ*(U^3)*(b + (R*a*ω(t)) / U) - Pgc(t) - Pge(t)) / ((J^2)*(ω(t)^2)))
# Q = 0.5A*R*a*Γ*ρ

# how to substitute 0.5A*R*a*Γ*ρ by Q in expr?
expr2 = substitute(expr, Dict([0.5A*R*a*Γ*ρ => Q]))

Result:

(Pgc(t) + Pge(t) - 0.5A*Γ*ρ*(U^3)*(b + (R*a*ω(t)) / U)) / (J*(ω(t)^2)) + (0.5A*R*a*Γ*ρ*(U^2)) / (J*ω(t))

Expected result:

(Pgc(t) + Pge(t) - 0.5A*Γ*ρ*(U^3)*(b + (R*a*ω(t)) / U)) / (J*(ω(t)^2)) + (Q*(U^2)) / (J*ω(t))

Related: #988

Discussion on Discourse: https://discourse.julialang.org/t/how-to-simplify-a-symbolic-expression/104381

@shashi
Copy link
Member

shashi commented Oct 6, 2023

I can implement something for this.

@ufechner7
Copy link
Author

That would be very kind! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants