Hello (sorry for my bad english)
I have a porblem when i want to remplace D(x)(0) with a expression (Xm*sin(w*t+omega) I need it to solve a differentiel equation using Laplace (I must use Laplace for the resolution)* When a use FL=subs(FL,diff(x(t),t),Xm*sin(w*t+omega)) i get the same expression and if a use s instead of t FL=subs(FL,diff(x(t),s),Xm*sin(w*t+omega)) i get D(x)(Xm*sin(w*t+omega) FL is the fuction i get after the transformation of Laplace
Please i need the responce as soon as possible

2 Commenti

Star Strider
Star Strider il 30 Ott 2016
Please post your original differential equation, and describe what you want to do.
zakaria bouzouf
zakaria bouzouf il 30 Ott 2016
Modificato: zakaria bouzouf il 30 Ott 2016
with x(0)=Xm*cos(tetta) and x'(0)=-Xm*w*sin(tetta)

Accedi per commentare.

 Risposta accettata

Star Strider
Star Strider il 30 Ott 2016
Modificato: Star Strider il 30 Ott 2016

1 voto

This works (although it uses a soon-to-be-deprecated single-quotes syntax in the subs call):
syms omega omega0 s x(t) Xm tetta
DE = diff(x,2) + omega0^2*x == 0;
LDE = laplace(DE, t, s);
LDE = subs(LDE, {'x(0)', 'D(x)(0)'}, {Xm*cos(tetta), -Xm*omega*sin(tetta)});
LDE = simplify(LDE, 'Steps', 20)
LDE =
omega0^2*laplace(x(t), t, s) + s^2*laplace(x(t), t, s) + Xm*omega*sin(tetta) == Xm*s*cos(tetta)
I usually work with control problems, where initial conditions are by convention zero. It is possible with the dsolve function to include specific initial conditions in the differential equation to be integrated. For some reason, similarly including initial conditions in laplace arguments is not possible.
I consider the inability to include initial conditions in a laplace call to be a ‘bug’ that needs to be corrected.
EDIT I submitted an Enhancement Request that the syntax for including initial conditions in the arguments be the same for both the dsolve and laplace functions. Let’s hope!

10 Commenti

zakaria bouzouf
zakaria bouzouf il 30 Ott 2016
Thank you it's work but i don't khow how to solve this equation to find the finil result
My pleasure.
If my Answer solves your problem, please Accept it.
-----
I am not certain what you mean by ‘solve’.
Your equation is already solved. All you have to do is to substitute values for the parameters and your time vector to calculate ‘x(t)’:
t = linspace(0, 2*pi, 250);
Xm = ...; % Insert Appropriate Value
W0 = ...; % Insert Appropriate Value
P0 = ...; % Insert Appropriate Value
x = Xm*cos(W0*t + P0);
If you are solving for the parameters, you need ‘x(t)’ defined for at least 3 different values of ‘t’ in order to calculate them. You can use the Symbolic Math Toolbox solve function for that, or the Optimization Toolbox fsolve function, or if you want to do it as curve-fitting, the nlinfit, lsqcurvefit, or fminsearch functions to estimate them.
zakaria bouzouf
zakaria bouzouf il 30 Ott 2016
I didn't how to do it sorry if you can put the following program i will be grateful
Star Strider
Star Strider il 30 Ott 2016
Please explain what you want to do. I explained how to solve it for ‘x(t)’.
zakaria bouzouf
zakaria bouzouf il 30 Ott 2016
After the first program you give i subs laplace(x(t),t,s)) with Lf and i get
LDE(t) =
(omega0^2 + s^2)*Lf(t) + Xm*omega*sin(tetta) - Xm*s*cos(tetta) == 0
My question is how to solve this equation to get the expression of Lf(t) with the others parameters to make a ilaplace to get the final result of x(t)
Your initial conditions should be scalars (in this instance), not functions. They are the values of the function and the derivative of the function, not functions themselves. I have changed them to ‘X0’ and ‘DX0’ here to clarify that.
Also, it used to be really easy to use Laplace transforms to solve differential equations in MATLAB, and about 10 years ago, I remember doing that frequently. I don’t know what changed or when, but now it takes much more effort than it should.
The Code:
syms omega omega0 s x(t) Xm tetta X0 DX0 X
DE = diff(x,2) + omega0^2*x == 0; % Differential Equation
LDE = laplace(DE, t, s) % Laplace Transform Of Differential Equation
LDE = subs(LDE, {'x(0)', 'D(x)(0)','laplace(x(t), t, s)'}, {X0, DX0, X}); % Substitute
X = solve(LDE,X) % Solve For ‘X’
X = simplify(X, 'Steps', 20) % Simplify
x_sol =
(DX0*sin(omega0*t) + X0*omega0*cos(omega0*t))/omega0
Just for fun, the dsolve solution:
Dx = diff(x);
x_dsol = dsolve(diff(x,2) + omega0^2*x, x(0) == X0, Dx(0) == DX0);
x_dsol = simplify(x_dsol, 'Steps', 20)
x_dsol =
(exp(-omega0*t*1i)*(DX0 - X0*omega0*1i)*1i)/(2*omega0) - (exp(omega0*t*1i)*(DX0 + X0*omega0*1i)*1i)/(2*omega0)
zakaria bouzouf
zakaria bouzouf il 30 Ott 2016
Thank you , now i can solve the problem
Star Strider
Star Strider il 31 Ott 2016
My pleasure.
Karan Gill
Karan Gill il 1 Nov 2016
Modificato: Karan Gill il 1 Nov 2016
One doesn't need to use single-quote syntax for "subs". Try
Dxt = diff(x,t);
LDE = subs(LDE, {x(0) Dxt(0)}, {Xm*cos(tetta) -Xm*omega*sin(tetta)})
Besides the substitution, could you explain why using Laplace transforms is harder now? That would be really helpful to know.
Karan (Symbolic Math documentation)
I didn’t use the syntax you did. That may have been part of the problem.
The other problem I had was in solving the Laplace-domain equation for ‘x(t)’:
LDE = subs(LDE, {'x(0)', 'D(x)(0)','laplace(x(t), t, s)'}, {X0, DX0, X}); % Substitute
For whatever reason, I found that third substitution (where ‘X’ is actually ‘X(s)’) necessary in order to actually solve the equation.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by