Solving a pair of equation using matlab

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
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
Amey Raj le 5 Oct 2021
See i get that but im not very good at MATLAB. I dont know how to solve this question using it as i have never written a code on it. I can solve it on paper without any issue but i have to use MATLAB for this question
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
Amey Raj le 5 Oct 2021
Modifié(e) : Amey Raj le 5 Oct 2021
Thanks for the suggestion. I looked up solve function and wrote this
syms y(t) t theta k m n
y(t) = k*exp(-t/2)*cos(theta + (3^(1/2)*t)/2);
Dy(t) = diff(y(t));
m = y(0) == 0;
n = Dy(0) == 1;
R = solve(m,n);
y(t) = R.k*exp(-t/2)*cos(R.theta + (3^(1/2)*t)/2);
This seems to work pretty well. If you have any suggestions regarding this code to reduce its size then pls tell. I am using new variables as i have to use them later. As is why I am writing this wierd code is because i have to write a program to find impulse response and total output of a countinuous LTIC system and my teacher didnt teach MATLAB just gave us an assignment on it and said to figure it out ourselves
Previous code works well for all the cases i tried but now i have a new issue
Let
y(t) = x^3 + x^2 + x + 1
a(t) = D + 6
so for example
y(t)*a(t) = D(x^3 + x^2 + x + 1) + 6(x^3 + x^2 + x + 1)
Here when i write
D(x^3 + x^2 + x + 1) => 3x^2 + 2x + 1
or D is the differential function
How would i write something like that in MATLAB?
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
Amey Raj
Amey Raj le 5 Oct 2021
Modifié(e) : Amey Raj le 5 Oct 2021
I could have done that but i have to write the code for something like
Let
y(x) = x^3 + x^2 + x + 1
a(x) is inputed by the user so for example if the user inputs
a(x) = D2 + D + 6
y(x)*a(x) = D2(x^3 + x^2 + x + 1) + D(x^3 + x^2 + x + 1) + 6(x^3 + x^2 + x + 1)
here D2(x^3 + x^2 + x + 1) = 6x + 2 and D is same as before. So D2 is double differential
Sorry about the t in previous comment. My bad
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by