How to plot a matrix with loop of input Variables

1 回表示 (過去 30 日間)
Muhammed Ajmal Pallithadathil Nazer
Muhammed Ajmal Pallithadathil Nazer 2017 年 11 月 22 日
編集済み: Joy Mondal 2017 年 11 月 23 日
I want to run the below code from the value of Bx 0 to 0.0118 with an interval of .00092 and plot it in e vs Bx, where e is a 4*1 matrix. I found some problem while plotting and I am very poor in working with loops.
Bx=0:.00092:0.0115;
B=0.5*1.978*0.467*30*Bx;
D=-7.31;
E=-1.71;
Bz=0.5*1.969*0.467*30*0;
A=[2*D+3*Bz,sqrt(3)*B,sqrt(3)*E,0;sqrt(3)*B,Bz,2*B,sqrt(3)*E;sqrt(3)*E,2*B,-Bz,sqrt(3)*B;0,sqrt(3)*E,sqrt(3)*B,2*D-3*Bz]
e=eig(A)
D=eig(A,'matrix')
plot(Bx,e)
Here I wrote the code straight away and may not be correct,

回答 (4 件)

Walter Roberson
Walter Roberson 2017 年 11 月 22 日
syms Bx
B=0.5*1.978*0.467*30*Bx;
D=-7.31;
E=-1.71;
Bz=0.5*1.969*0.467*30*0;
A=[2*D+3*Bz,sqrt(3)*B,sqrt(3)*E,0;sqrt(3)*B,Bz,2*B,sqrt(3)*E;sqrt(3)*E,2*B,-Bz,sqrt(3)*B;0,sqrt(3)*E,sqrt(3)*B,2*D-3*Bz]
e=eig(A)
fplot(e, [0, 0.0115])
  1 件のコメント
Muhammed Ajmal Pallithadathil Nazer
Muhammed Ajmal Pallithadathil Nazer 2017 年 11 月 22 日
Thank you, but it seems to take the Bx only the value of 0.0115 instead of the other values from 0 at a regular interval of .00092. Simply, it continuously plot the value of 0.0115 from 0 to 0.0115. Moreover, the answer from Joy Mondal works well.
  • Item one
  • Item two

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


Joy Mondal
Joy Mondal 2017 年 11 月 22 日
Please try this code
  1 件のコメント
Muhammed Ajmal Pallithadathil Nazer
Muhammed Ajmal Pallithadathil Nazer 2017 年 11 月 22 日
Thank you Joy. Your code is working well. It would be great if you share how to change the scale of x and y axis in the graph as well as different colour for four different values of e as it quite difficult to identify from the graph

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


Joy Mondal
Joy Mondal 2017 年 11 月 22 日
  • clear all
  • clc
  • for Bx=0:.00092:0.0115
  • i=0;
  • B=0.5*1.978*0.467*30*Bx;
  • D=-7.31;
  • E=-1.71;
  • Bz=0.5*1.969*0.467*30*0;
  • A=[2*D+3*Bz,sqrt(3)*B,sqrt(3)*E,0;
  • sqrt(3)*B,Bz,2*B,sqrt(3)*E;
  • sqrt(3)*E,2*B,-Bz,sqrt(3)*B;
  • 0,sqrt(3)*E,sqrt(3)*B,2*D-3*Bz];
  • e=eig(A);
  • j=0;
  • for i=1:4
  • j=j+1;
  • ei=e(i,1);
  • plot(Bx,ei,'ok')
  • hold on
  • end
  • end
  2 件のコメント
Stephen23
Stephen23 2017 年 11 月 22 日
@Joy Mondal: please format your code correctly. It is very simple: first select the code text, then click the {} Code button above the textbox.
Joy Mondal
Joy Mondal 2017 年 11 月 23 日
編集済み: Joy Mondal 2017 年 11 月 23 日
Thanks Stephen.

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


Joy Mondal
Joy Mondal 2017 年 11 月 23 日
編集済み: Joy Mondal 2017 年 11 月 23 日
clc
clear all
for Bx=0:.00092:0.0115
i=0;
B=0.5*1.978*0.467*30*Bx;
D=-7.31;
E=-1.71;
Bz=0.5*1.969*0.467*30*0;
A=[2*D+3*Bz,sqrt(3)*B,sqrt(3)*E,0;
sqrt(3)*B,Bz,2*B,sqrt(3)*E;
sqrt(3)*E,2*B,-Bz,sqrt(3)*B;
0,sqrt(3)*E,sqrt(3)*B,2*D-3*Bz];
e=eig(A);
j=0;
for i=1:4
j=j+1;
ei=e(i,1);
if j==1
plot(Bx,ei,'dk')
elseif j==2
plot(Bx,ei,'og')
elseif j==3
plot(Bx,ei,'sb')
elseif j==4
plot(Bx,ei,'xm')
end
hold on
end
end
end

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by