フィルターのクリア

Retrieve vector within function file

2 ビュー (過去 30 日間)
prabhjeet singh
prabhjeet singh 2021 年 3 月 31 日
コメント済み: prabhjeet singh 2021 年 3 月 31 日
x = 10';
tspan = [0 10];
[t,x]= ode45(@fun,tspan,x);
[~, u] = fun(t.',x.');
figure(1)
plot(t,u,'-k','Linewidth',1.5);
and function file is
function [dot,u] = fun(~,x)
k = 1;
p = 10;
x = x(1);
u = (-k.*x + x.^3 - p.*x^2) ./ x;
xdot = -x.^3 + p.*x.^2 + x.*u;
dot = xdot';
When I try to plot t with u, I am not getting a plot because input u is not getting saved as vector.
Is there any way that u can be saved as a vector here?
Thanks

採用された回答

VBBV
VBBV 2021 年 3 月 31 日
function [dot,u] = fun(~,x)
k = 1;
p = 10;
%x = x(1);
x
u = (-k.*x + x.^3 - p.*x.^2) ./ x;
xdot = -x.^3 + p.*x.^2 + x.*u;
dot = xdot';
  2 件のコメント
VBBV
VBBV 2021 年 3 月 31 日
編集済み: VBBV 2021 年 3 月 31 日
Comment the line
%x = x(1);
Rune it again with a small change below line in function
u = (-k.*x + x.^3 - p.*x.^2) ./ x; % need element wise power operator
prabhjeet singh
prabhjeet singh 2021 年 3 月 31 日
Thankyou very much VBBV. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by