フィルターのクリア

Warning: Imaginary parts of complex X and/or Y arguments ignored

5 ビュー (過去 30 日間)
hani daniel
hani daniel 2016 年 2 月 24 日
コメント済み: hani daniel 2016 年 2 月 25 日
function main
options=odeset('RelTol',1e-06)
Xo = [1;0];
tspan = [0,5];
[t,X] = ode45(@TestFunction,tspan,Xo,options);
figure
hold on
plot (t,X(:,1));plot (t,X(:,2),':')
legend ('x1','x2');ylabel('x');xlabel('t')
return
function dx_dt=TestFunction(t,x)
%function which returns a rate of change vector
M=[i,i;i,i]
dx_dt=M*x;
return
full error message:
Warning: Imaginary parts of complex X and/or Y arguments ignored
> In ode_plot_6 (line 17)
The program plots the graph, but generates the above error. Please help in eliminating the error message. Thank you.
  1 件のコメント
Rick Rosson
Rick Rosson 2016 年 2 月 24 日
Please format your code so that it is readable.

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 2 月 24 日
You know that in
M=[i,i;i,i]
that the "i" there is going to refer to sqrt(-1) ? You are going to get complex output, and MATLAB cannot display complex output when you use that plotting syntax.
You could use
plot (t, real(X(:,1)), 'b-', t, imag(X(:,1)), 'r-');
plot (t, real(X(:,2)), 'b:', t, imag(X(:,2)), 'r:')
This would plot the real components in blue and the imaginary components in red.
  1 件のコメント
hani daniel
hani daniel 2016 年 2 月 25 日
Walter, Thank you for your help in clarifying the issue. Regards HD

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by