Can I substitute boundary conditions into a syms function?

2 views (last 30 days)
Is there anyway to substitute calculated boundary values back into the expression? For a simple straightforward example consider:
syms v(x) a0 a1 a2 a3 x
v(x)=a0+a1*x+a2*x^2+a3*x^3
dv=diff(v)
BC1=v(0)==0
BC2=dv(0)==0
This returns:
v(x) =
a3*x^3 + a2*x^2 + a1*x + a0
dv(x) =
3*a3*x^2 + 2*a2*x + a1
BC1 =
a0 == 0
BC2 =
a1 == 0
How can I now substitute the calculated conditions of BC1 and BC2 back into v?
The command subs requires that I already know what variable and value I want to substitute for. Is there anyway to use the returned expression of a0==0 and a1==0 to make a0=0 and a1=0 in v(x)? Thanks for the help.

Answers (1)

Adarsh
Adarsh on 31 Jan 2025
Hi @Joe I,
Based on the explanation I assume you are trying to substitute the assumptions from the solved equations into the original expression.
To achieve the required functionality, you can explore the “assume” & “assumeAlso” functions in the MATLAB documentation.
These functions can be used to make any assumptions of conditions. By giving the output of the solved equations as an argument to these functions, the assumptions would be set accordingly.
Now the “simplify” function can be used on the original expression which substitutes the resulting values of the assumptions into the expression, achieving the required functionality.
Here is an example code demonstrating the usage of “assume” & “assumeAlso”to achieve the required functionality:
syms v(x) a0 a1 a2 a3 x % creating symbolic variables
v(x)=a0+a1*x+a2*x^2+a3*x^3 % assigning expression to v(x)
v(x) = 
dv=diff(v) % differentiating v(x)
dv(x) = 
assume(v(0)==0) % assuming v(0)==0
assumeAlso(dv(0)==0) % assuming dv(0)==0
assumptions % displaying all assumptions till now
ans = 
simplify(v(x))% using simplify to substitute the assumptions in the expression
ans = 
For more information, the documentation for the “assume” function can be referred using the link below:
Hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!