Creating an array of dependent symbolic variable

Hi,
I need to create 'N' equations based on user input 'N' which is a natural number.
Each equation is supposed to have a variable A which is a dependent on x. This 'A' term is different for each equation. Equation1 will have A1, equation2 will have A2 and so on.
I am creating this term using the expresion below.
A = sym('A', [1 N]);
This gives me symbolic variables A1, A2, A3... AN. But the problem is these terms are just symbolic variables and not dependent on x. So if I differentiate the equation with respect to x, these terms dissappear. If I use A(x) to create the variable (like a normal dependent variable), it returns a 1x1 symbolic function instead of 1xN symbolic variables.
A(x) = sym('A', [1 N]);
The above equation creates 1xN symbolic variables but the output is of type 1x1 symbolic function. Is there a way to isolate each term from this function or is there any other way to create a dependent variable array.
Thanks

댓글 수: 2

What’s your application by your idea?
Abinav
Abinav 2020년 10월 13일
I have 'N' sections and each section has an equation.
The equations have some common terms and different terms which depend on the boundary conditions. I am creating those equations through a loop and conditional statements which will be solved later. So, I need the variable 'A' to be an array so that I can add it to the equations while iterating through the loop.

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

 채택된 답변

madhan ravi
madhan ravi 2020년 10월 13일
편집: madhan ravi 2020년 10월 13일

0 개 추천

A(x) = str2sym(regexprep(char(A), '(\_?\d)+', '$0(x)'))

댓글 수: 3

Abinav
Abinav 2020년 10월 13일
It again creates a 1x1 symbolic function with all the elements of the vector. I can't select the individual elements anymore.
madhan ravi
madhan ravi 2020년 10월 13일
편집: madhan ravi 2020년 10월 13일
A(x) = str2sym("A" +(1:N)+"(x)")
Wanted = formula(A)
Wanted(2)
[Too many edits in mobile is so painful ;)]
Abinav
Abinav 2020년 10월 14일
Thanks. It worked.
Sorry to put you through that.

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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 10월 13일

0 개 추천

syms A [1 2]
eq1 = A(1)+2*A(2) == 42
eq2 = 3*A(1)-4*A(2) == 99
S = solve(eq1, eq2)
A1 = S.A1
A2 = S.A2
subs(eq1)

댓글 수: 1

Abinav
Abinav 2020년 10월 13일
I think you didn't get my question.
I need to create an array of dependent symbolic varaible, not just symbolic variables. Something like
A = [A1(x) A2(x) A3(x)]

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2020년 10월 13일

댓글:

2020년 10월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by