Extract solution from struct

52 views (last 30 days)
Ali Awada
Ali Awada on 6 Dec 2020
Answered: Asvin Kumar on 9 Feb 2021
Hello,
I have the following code to solve a system in an abstract form. The solution is stored in a struct. Can someone help me extract the array(c1, c2, and c3 as a function ot the other terms):
syms h1 h2 mu1 mu2 c1 c3 c4 V
[M]=[(h1+h2)*c3+c4; c3*h1+c4;mu1*mu2*c3]
[L]=[V;c1*h1;mu2*c3]
solution=[L]-[M]
Thanks

Answers (1)

Asvin Kumar
Asvin Kumar on 9 Feb 2021
The setup looks good. You can use the solve function to find the solutions to a given symbolic equation as shown in this example. Here's some sample code:
s = solve(solution==0, [c1 c3 c4]) % substitute 0 for values you have stored in a struct
% same as
% s = solve(solution, [c1 c3 c4])
s =
struct with fields:
c1: [1×1 sym]
c3: [1×1 sym]
c4: [1×1 sym]
s.c1
s.c2
s.c3
ans =
V/h1
ans =
0
ans =
V

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by