Solving symbolic array.

조회 수: 4 (최근 30일)
Kristian Dimitrov
Kristian Dimitrov 2024년 6월 30일
편집: Torsten 2024년 6월 30일
I am working with symbolic vector of 1xN size. The vector contains N eqations in the from of
X == a + b + c
Y == X*(d + e + f)
Z == Y + X
I am suing subs to substitute the coefficients a b c d e f with numeric values. The result is in the form of
X == g
Y ==X*h
Z == Y +X
It sould be quite straigh forward to solve for Z since all variables are numeric, but for crying out loud I cannot make matlab to solve for Z.
Any ideas?
  댓글 수: 2
Torsten
Torsten 2024년 6월 30일
Please include your code so far.
Kristian Dimitrov
Kristian Dimitrov 2024년 6월 30일
편집: Kristian Dimitrov 2024년 6월 30일
This are the type of inputs that i am using
syms a b c d e
eqn = transpose(str2sym("[X == a+b+c, Y == X*(d+e), Z == X+Y]"));
eqn_S = subs(eqn,{a,b,c,d,e},{[1 2 3 4 5]});
and the outout i am getting
eqn_S =
X == 6
Y == 9*X
Z == X + Y
I tried vpa solve etc. but cannot find syntaxis that works properly to solve for Z.
One way i tried to solve it to solve each row separately and substitute its value in the following equations, but there must be more elegant solution to the problem.

댓글을 달려면 로그인하십시오.

채택된 답변

Kristian Dimitrov
Kristian Dimitrov 2024년 6월 30일
vpasolve works perfetcly to solve it numerically.
syms a b c d e
eqn = transpose(str2sym("[X == a+b+c, Y == X*(d+e), Z == X+Y]"));
eqn_S = subs(eqn,{a,b,c,d,e},{[1 2 3 4 5]});
vpasolve(eqn_S)
  댓글 수: 1
Torsten
Torsten 2024년 6월 30일
편집: Torsten 2024년 6월 30일
syms a b c d e X Y Z
eqn = transpose(str2sym("[X == a+b+c, Y == X*(d+e), Z == X+Y]"))
eqn = 
sol = solve(eqn,[X,Y,Z]);
sol = struct with fields:
X: a + b + c Y: (d + e)*(a + b + c) Z: a + b + c + a*d + a*e + b*d + b*e + c*d + c*e
sol.Z = simplify(sol.Z)
sol = struct with fields:
X: a + b + c Y: (d + e)*(a + b + c) Z: (d + e + 1)*(a + b + c)
subs(sol,[a,b,c,d,e],[1,2,3,4,5])
ans = struct with fields:
X: 6 Y: 54 Z: 60

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by