Filter löschen
Filter löschen

Extract solution from struct

7 Ansichten (letzte 30 Tage)
Ali Awada
Ali Awada am 6 Dez. 2020
Beantwortet: Asvin Kumar am 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

Antworten (1)

Asvin Kumar
Asvin Kumar am 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

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by