ode,dsolve,spline,ode interp, differantial

1 visualización (últimos 30 días)
esat gulhan
esat gulhan el 4 de Ag. de 2020
Comentada: esat gulhan el 4 de Ag. de 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?

Respuesta aceptada

John D'Errico
John D'Errico el 4 de Ag. de 2020
Editada: John D'Errico el 4 de Ag. de 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)

Más respuestas (1)

Alan Stevens
Alan Stevens el 4 de Ag. de 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

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by