Extract solution from struct

조회 수: 37 (최근 30일)
Ali Awada
Ali Awada 2020년 12월 6일
답변: Asvin Kumar 2021년 2월 9일
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

답변 (1개)

Asvin Kumar
Asvin Kumar 2021년 2월 9일
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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by