Solving a pair of equation using matlab
Afficher commentaires plus anciens
how to solve the following pair of equation using MATLAB
y(t) = k*exp(-t/2)*cos(theta + (3^(1/2)*t)/2)
y(t = 0) = 0
Dy(t = 0) = 1
Solve for "k" and "theta"
Dy(t) mean differenttiation of function y(t) w.r.t t
Also return y(t) with values of k and theta inserted
Réponses (1)
Bjorn Gustavsson
le 5 Oct 2021
0 votes
You have 2 unknown parameters k and theta. You have one condition for y at t=0 and one condition for dy/dt at t=0. Since you have an explicit expression for y(t) you can differentiate that to give you an explicit expression for dy/dt. That will result in 2 expressions for y and dy/dt. This should make it possible to determine the 2 parameters. Simply start by manually differentiating y(t) unsing the product rule.
HTH
7 commentaires
Amey Raj
le 5 Oct 2021
Bjorn Gustavsson
le 5 Oct 2021
OK, to me this seems like a very odd task for a matlab-beginner - we would typically start by numerical computations of all kinds, leading to integrals and integration of differential equations etc - and then perhaps a bit of symbolic computations.
If you're a matlab-beginner start with looking through the on-ramp material: on-ramp_1, on-ramp_2. That will bring you up to speed on what you feel you need faster than what you'll get here.
As for forcing someone to solve this problem with matlab you could try something like:
sym y t theta k % Define the variables as symbolic
y = k*exp(-t/2)*cos(theta + (3^(1/2)*t)/2);
Then have a look at the help for diff (the symbolic version) which will show you how to differentiate y. After that you will have one expression for y and one expression for Dy. Those you can turn into 2 equations for the conditions at t=0, then it is very straightforward to solve those two equations and the equation t==0 using solve (see help and documentation for solve for examples). Now I've given you sufficient information to work this out, if I give you more I'll do the entire task for you which would hamper your matlab-development...
HTH
Amey Raj
le 5 Oct 2021
Bjorn Gustavsson
le 5 Oct 2021
First (I guess), your definition of y is independent of t - unless x depends on t somehow.
If you want to have a differential equation of the type dy/dt + 6*y = RHS you might have to live with something more explicit:
my_ode = diff(y,t) + 6*y == RHS;
HTH
Bjorn Gustavsson
le 5 Oct 2021
Then the question becomes more of "how to parse user input and interpret that" - once that is solved it should be comparatively easy to build a sum of derivatives of a polynomial or a differential equation. I suggest you open a new question on that.
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!