필터 지우기
필터 지우기

ode,dsolve,spline,ode interp, differantial

조회 수: 4 (최근 30일)
esat gulhan
esat gulhan 2020년 8월 4일
댓글: esat gulhan 2020년 8월 4일
x=[0:0.5:3]
M=[0 1 4.5 12.75 25 41 62]
dQ/dx=M
How can i solve this diff equation. My code is below
x=[0:0.5:3]
M=[0 1 4.5 12.75 25.1 41 62]
k=spline(x,M)
[x,Q] = ode45(@(x,Q) k, [0 3], 0);
it does not work
I dont have function ı have data x and data M. I use these datas with spline.
is there any way to solve this question in ODE, dsolve, deval or anything else?

채택된 답변

John D'Errico
John D'Errico 2020년 8월 4일
편집: John D'Errico 2020년 8월 4일
You are not asking to do anything more than to integrate a spline, and perhaps to plot the result as a function of x. (You don't really say what you wanted to do with it.)
If you have the curve fitting toolbox, then fnint will do the integral directly, with the result as another higher order spline. So
x = [0:0.5:3];
M = [0 1 4.5 12.75 25 41 62];
spl = spline(x,M);
splint = fnint(spl);
fnplt(splint)
So these lines are suffcient to do what you wanted. Note the use of semi-colons at the end of lines.
By the way, your code will improve when you begin to use variable names that have some meaning in context. So instead of naming a spline k, use a descriptive name. Then when you need to debug your code next month or next year, you will be able to read your own code more easily.
If you don't have the curve fitting toolbox, or are not allowed to use fnint and fnplt, or you really want to use ode45, that too is not difficult. You need to learn then to use functions properly, and how to pass in arguments to functions.
x = [0:0.5:3];
M = [0 1 4.5 12.75 25 41 62];
spl = spline(x,M);
odefun = @(t,y) ppval(spl,t);
y0 = 0;
xspan = linspace(x(1),x(end),100);
[xout,yout] = ode45(odefun,xspan,y0);
plot(xout,yout)

추가 답변 (1개)

Alan Stevens
Alan Stevens 2020년 8월 4일
More like this perhaps:
xspan = [0 3];
Q0 = 0;
[x, Q] = ode45(@f, xspan, Q0);
plot(x,Q), grid
xlabel('x'), ylabel('Q')
function dQdx = f(x,~)
X=0:0.5:3;
M=[0 1 4.5 12.75 25 41 62];
dQdx = spline(X,M,x);
end

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by