![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/341128/image.jpeg)
ode,dsolve,spline,ode interp, differantial
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
esat gulhan
am 4 Aug. 2020
Kommentiert: esat gulhan
am 4 Aug. 2020
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?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 4 Aug. 2020
Bearbeitet: John D'Errico
am 4 Aug. 2020
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/341128/image.jpeg)
Weitere Antworten (1)
Alan Stevens
am 4 Aug. 2020
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
Siehe auch
Kategorien
Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!