How to define a dependent variable for differentiaion?

조회 수: 7 (최근 30일)
Abinav
Abinav 2020년 10월 7일
댓글: Ameer Hamza 2020년 10월 7일
Hi,
I have a variable A which is dependent on x, but I don't know the expression yet.
I have a differential equation dA/dx which is given as
dA_x = (T*b-E*Q*diff(C_s,x))/(E*S);
All the entities except C_s are constants. I can get A by integrating this equation.
A = int(dA_x,x);
But the problem lies with the differential expression of C_s which is given by
C_s = (M-2*A*E*Q)/(2*E*I);
Since A is not yet defined as a function or dependent variable of x, the differentiation results in 0.
How do I solve this?
I'm not looking for a numeriacal answer, I just need a symbolic expression.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 7일
Define symbolic variable A like this
syms A(x)
It will tell MATLAB that a depends on x and will not become zero on differentiation.
  댓글 수: 6
Abinav
Abinav 2020년 10월 7일
syms L b h S I Q E u F M T c theta w k
syms x A(x) dA_x C_s(x)
S = b*h;
I = b*h^3/3;
Q = b*h^2/2;
M = -((F*L^2)/2)+(F*(L*x-x^2/2));
C_s = (M-2*A*E*Q)/(2*E*I);
dA_x = (T*b-E*Q*diff(C_s,x))/(E*S);
A = int(dA_x,x);
At this point, the diff(C_s,x) becomes C_s. And matlab makes a substitution from the above equation resulting in A(x) on both sides of equation. Which is mathematically correct.
C_s = subs(C_s,A)
But when I substitute A back into my C_s, there is still an A term in the equation. This could be avoided if matlab retains keeps the term as C_s while integrating instead of substituing the equation in there.
In either case, the problem can be solved by rearranging the terms but I can't figure out a way to do that in Matlab.
Ameer Hamza
Ameer Hamza 2020년 10월 7일
Symbolic variables can be a bit confusing sometimes. For this case, the following code will work
syms L b h S I Q E u F M T c theta w k
syms x A(x) dA_x(x) C_s(x)
S = b*h;
I = b*h^3/3;
Q = b*h^2/2;
M = -((F*L^2)/2)+(F*(L*x-x^2/2));
C_s = (M-2*A*E*Q)/(2*E*I);
dA_x = (T*b-E*Q*diff(C_s,x))/(E*S);
A = int(dA_x,x);
C_s = subs(C_s);

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by