How to solve an expression with multiple variables using input values substitution?

1 view (last 30 days)
I have a long 5th degree polynomial in S with numerator and denominator expressions. It however has several other variables such as R1,L1,L2,C1 so on. I would like to solve the expression for a given input values of the variables R1,L1, etc. The answer will however be still be an equation in S (a transfer function). How do I implement this in matlab.
A simplified example would be as follows:
expression is: R1L2 + L1*C2^2*S + (2L1-C1R1)*S^2
I can give input: R1=1, L1=2, L2=2.5, C1=1.5, C2=3
Then the output will be: 2.5 + 18S + 2.5S^2
the end goal is to be able perform ilaplace and fplot on the output (which is supposed to be a transfer function), as shown here. I am guessing that means the output expression above needs to be in or converted to symbolic form for me to do rest of the operations.

Answers (1)

Shishir Reddy
Shishir Reddy on 26 Dec 2024
Edited: Shishir Reddy on 26 Dec 2024
Hi Sunny
To solve this problem in MATLAB, symbolic math can used to substitute the given values into the polynomial expression, and then operations like the inverse Laplace transform and plotting are performed. Here's how you can achieve this.
1. Define the symbolic variables and expression.
syms S R1 L1 L2 C1 C2
expression = R1*L2 + L1*C2^2*S + (2*L1 - C1*R1)*S^2
expression = 
2. Substitute the given values into the expression.
R1_val = 1;
L1_val = 2;
L2_val = 2.5;
C1_val = 1.5;
C2_val = 3;
expression_substituted = subs(expression, [R1, L1, L2, C1, C2], [R1_val, L1_val, L2_val, C1_val, C2_val])
expression_substituted = 
3. Perform inverse Laplace transform
time_domain_expression = ilaplace(expression_substituted, S);
disp(time_domain_expression);
For more information regarding syms, kindly refer the following documentation -
I hope this helps.

Products

Community Treasure Hunt

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

Start Hunting!