Plotting the derivative of a non symbolically defined function

I've solved a second order nonlinear differential equation in matlab and would like to plot it's derivative:
my attempts so far:
syms phi(t)
figure
hold on
for v =1:10
[V] = odeToVectorField(diff(phi,2)== 28*(0.45-0.136)-(0.9)^2 * 0.45*1.21*sqrt(2)*v^2*sin(phi)*sin(pi/4-phi)/(4*0.25));
M = matlabFunction(V,'vars', {'t','Y'});
sol = ode45(M,[0 20],[0 5]);
fplot(@(x)deval(sol,x,1), [0, 20])
end
ddt = gradient(phi(:)) ./ gradient(t(:));
fplot(ddt)
Doing this returns an error. I've also tried
y =diff(phi)
fplot(y)
which just does nothing.
Any help would be great!

2 件のコメント

VBBV
VBBV 2020 年 11 月 8 日
Can you show the error ?
Louis Sharma
Louis Sharma 2020 年 11 月 8 日
hi,
Error:
Error using symfun/subsref
Invalid argument at position 2. Symbolic function indexing evaluates the function at the input arguments. To perform colon indexing call FORMULA before indexing.

サインインしてコメントする。

 採用された回答

Alan Stevens
Alan Stevens 2020 年 11 月 8 日

0 投票

You could just do it totally numerically:
phi0 = 0;
dphidt0 = 5;
IC = [phi0 dphidt0];
tspan = 0:0.1:20;
v = 1:10;
phi = zeros(numel(tspan),numel(v));
dphidt = zeros(numel(tspan),numel(v));
for i = 1:numel(v)
[t, Y] = ode45(@(t,Y) odefn(t,Y,v(i)),tspan, IC);
phi(:,i) = Y(:,1);
dphidt(:,i) = Y(:,2);
lgndstr = sprintf('v = %2i \n',i);
lgnd(i,:) = lgndstr;
end
figure(1)
plot(t,phi),grid
xlabel('t'),ylabel('\phi');
legend(lgnd)
figure(2)
plot(t,dphidt),grid
xlabel('t'),ylabel('d\phi dt');
legend(lgnd)
function dYdt = odefn(~,Y,v)
phi = Y(1);
dphidt = Y(2);
dYdt = [dphidt;
28*(0.45-0.136)-(0.9)^2*0.45*1.21*sqrt(2)*v^2*sin(phi)*sin(pi/4-phi)/(4*0.25)];
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2020b

質問済み:

2020 年 11 月 8 日

回答済み:

2020 年 11 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by