필터 지우기
필터 지우기

Rename integration variable in symbolic result

조회 수: 2 (최근 30일)
Mohamed Gharbi
Mohamed Gharbi 2022년 9월 18일
편집: Surya 2023년 2월 27일
Hi,
There is an ambiguity in the name of vaiable x.
In the code below, I use x is a function of the variable t and Matlab uses it as the variable of integration.
How to change the name of the variable of integration ?
syms t m b y(t) y0 C x(t) % definitions of symbolic variables
cond = y(0) == C % inital condition
ode = m*diff(y,t) + b*y(t) == x(t) % definition of differential equation
ySymbSol(t) = dsolve(ode, cond) % Solution of the differential equation which uses x as integration variable !
The same result is obtained with Matlab 2022a and 2022b.
  댓글 수: 3
Mohamed Gharbi
Mohamed Gharbi 2022년 9월 19일
Yes. but in the book I'm writing, I use as notation for linear systems x(t) for input and y(t) for output. I would like, if possible, to keep these notations.
Torsten
Torsten 2022년 9월 19일
I doubt you can specify it easily.

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

채택된 답변

Paul
Paul 2023년 2월 24일
I don't know if I'd call this 'easily', but it gets the desired result (I believe).
syms t m b y(t) y0 C x(t) % definitions of symbolic variables
cond = y(0) == C; % inital condition
ode = m*diff(y,t) + b*y(t) == x(t); % definition of differential equation
syms u(t)
ySymbSol(t) = dsolve(subs(ode,x(t),u(t)), cond) % Solution of the differential equation which uses x as integration variable !
ySymbSol(t) = 
syms syms x tau
ySymbSol(t) = changeIntegrationVariable(ySymbSol(t),x,tau)
ySymbSol(t) = 
syms u
ySymbSol(t) = subs(ySymbSol(t),u,x)
ySymbSol(t) = 
syms x(t)
  댓글 수: 1
Torsten
Torsten 2023년 2월 25일
We say: From behind through the chest into the eye :-)

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

추가 답변 (1개)

Surya
Surya 2023년 2월 23일
Hi,
To avoid the ambiguity in the variable name, you can use a different variable for integration in the dsolve command. You can do this by providing the integration variable as the second argument to the dsolve function. Here's an example:
syms t m b y(t) y0 C x(t) tau
cond = y(0) == C; % initial condition
ode = m*diff(y,t) + b*y(t) == x(t); % definition of differential equation
ySymbSol(tau) = dsolve(ode, cond, tau); % solve the ODE with respect to tau
In this example, the dsolve function is called with the third argument set to tau, which specifies that tau is the independent variable in the differential equation. The second argument t is used as the integration variable in the solution. The resulting ySymbSol function will depend on tau instead of t.
  댓글 수: 3
Surya
Surya 2023년 2월 24일
편집: Surya 2023년 2월 27일
Here x(t) is renamed as g(t)
syms t m b y(t) y0 C g(t) % definitions of symbolic variables
cond = y(0) == C % inital condition
ode = m*diff(y) + b*y(t) == g(t) % definition of differential equation
ySymbSol(t) = dsolve(ode, cond)
And here is the final function
Now x becomes the variable of integration and g(x) is the function of x taking values from [ 0, t ].
Hope it helps.
Torsten
Torsten 2023년 2월 24일
See my discussion with the OP after the original question:
My comment was:
Should be easier to rename your function x, shouldn't it ?
And his answer was:
Yes. but in the book I'm writing, I use as notation for linear systems x(t) for input and y(t) for output. I would like, if possible, to keep these notations.
And my comment was:
I doubt you can specify it easily.
Or is it possible to specify it easily ?

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

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by