필터 지우기
필터 지우기

how can I create a matrix from calculated answers

조회 수: 6 (최근 30일)
P
P 2011년 2월 26일
I have this answers and I want to put them in a diagonal matrix.Pls help me!
y =
0.0025 + 0.0155i
y =
0.0030 + 0.0171i
y =
0.0038 + 0.0191i
y =
0.0049 + 0.0216i
y =
0.0066 + 0.0248i
y =
0.0092 + 0.0289i
y =
0.0137 + 0.0344i
y =
0.0220 + 0.0414i
y =
0.0388 + 0.0487i
y =
0.0717 + 0.0450i
y =
1000000
y =
0.0717 - 0.0450i
y =
0.0388 - 0.0487i
y =
0.0220 - 0.0414i
y =
0.0137 - 0.0344i
y =
0.0092 - 0.0289i
y =
0.0066 - 0.0248i
y =
0.0049 - 0.0216i
y =
0.0038 - 0.0191i
y =
0.0030 - 0.0171i
y =
0.0025 - 0.0155i
  댓글 수: 2
James Tursa
James Tursa 2011년 2월 26일
Can you show the code that generates these numbers? You can pre-allocate a result and then assign them to the appropriate spots in the result, or maybe there is a better vectorized solution, but we can't tell without seeing your code.
P
P 2011년 2월 26일
clear all;
f=1E3;
L1=1E-3;
L2=100;
Rs=1E-6;
R1=10;
w=2*pi*f;
k=10;
z1=eye(21);
for a = -11:k-1
omega = w*(a+1);
z=Rs+[j*omega*L2*((R1+j*omega*L1))]/[R1+j*omega*(L1+L2)];
y=1/z
end

댓글을 달려면 로그인하십시오.

채택된 답변

Matt Fig
Matt Fig 2011년 2월 26일
Don't you think it would help if you showed us how that "this answers" was generated? It really would.
.
.
.
.
.
.
EDIT
O.k., here is one way, with your FOR loop:
clear all
f=1E3;
L1=1E-3;
L2=100;
Rs=1E-6;
R1=10;
w=2*pi*f;
k=10;
z1=eye(21); % I assume you want this to be the matrix.
cnt = 1;
for a = -11:k-1
omega = w*(a+1);
z1(cnt,cnt)=1/(Rs+(j*omega*L2*((R1+j*omega*L1)))/(R1+j*omega*(L1+L2)));
cnt = cnt + 1;
end
Or, simpler:
f=1E3;
L1=1E-3;
L2=100;
Rs=1E-6;
R1=10;
w=2*pi*f;
k=10;
omega = w*((-11:k-1)+1);
z1_2 = diag(1./(Rs+(j*omega*L2.*((R1+j*omega*L1)))./(R1+j*omega*(L1+L2))));
Now if you compare z1 and z1_2, you will see that they are equal.
  댓글 수: 2
Matt Tearle
Matt Tearle 2011년 2월 26일
??? Undefined function or variable read_my_mind
Stupid MATLAB.
P
P 2011년 2월 26일
Matt Fig is awesome!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

P
P 2011년 2월 26일
here is the code, I've tried to multiply "y" with "z1" but it was a bad idea:)
clear all; f=1E3; L1=1E-3; L2=100; Rs=1E-6; R1=10; w=2*pi*f; k=10; z1=eye(21);
for a = -11:k-1 omega = w*(a+1); z=Rs+[j*omega*L2*((R1+j*omega*L1))]/[R1+j*omega*(L1+L2)]; y=1/z
end

Matt Tearle
Matt Tearle 2011년 2월 26일
M = zeros(n);
for k = 1:n
% calculate y
M(k,k) = y;
end
Or, preferably, if you can calculate all the y values in a vector, as explained here you can then do
M(1:n+1:end) = y;
Edit: fixed typo ( n+1 instead of n )
  댓글 수: 4
P
P 2011년 2월 26일
Thanks a lot, finally I can go on with my project.
Matt Tearle
Matt Tearle 2011년 2월 27일
Oops, thanks James for catching the typo.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by