Solving a differential equation using matlab
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Andreas Volden
le 14 Oct 2014
Commenté : Star Strider
le 15 Oct 2014
Hi!
I have the following differential equation where x is unknown and p_dot is the derivative of p(p is given):
x * p_dot = qa -qb.
The vectors qa, qb and p are given by samples of 1 sec, and n samples. In this case n = 3597.
To find x, I've tried several procedures, none that actually works. One challenge for me is to find the derivative of p. Using both matlab and simulink has given me no logical answers. I've also tried the other way around, by integrating both sides of the equal sign. This also gives faulty answers.
Anyone who can provide som hint/tips, especialy some coding examples, would be appreciated!
Cheers
0 commentaires
Réponse acceptée
Star Strider
le 15 Oct 2014
I am not certain that I understand what you want to do, so see if this approximates it:
p = linspace(0,50,25) + rand(1,25)*0.01; % Create Data
qa = randi(10,1,25); % Create Data
qb = randi(20,1,25); % Create Data
p_dot = gradient(p); % Create ‘p_dot’
x = (qa - qb)./p_dot; % Solve For ‘x’
2 commentaires
Star Strider
le 15 Oct 2014
My pleasure!
Without knowing more about your data and what you want to do, I cannot be specific. (A sample of your data would be helpful.) If x is supposed to be a constant, one possibility might be to do a linear regression, for instance:
x = [ones(size(p))' p_dot']\[qa' - qb']; % Solve For ‘x’
This replaces my previous line calculating ‘x’. It gives two scalar values, a slope ‘x(1)’ and an intercept ‘x(2)’, but it might be what you want. Note that this assumes all your original vectors are row vectors, so they need to be transposed to column vectors to work in the regression equation (thus the transpose (') operators).
Does this do what you want?
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!