Solving a differential equation using matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2014년 10월 15일
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
Star Strider
2014년 10월 15일
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?
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!