필터 지우기
필터 지우기

While taking large range error is occur. How to solve this problem?

조회 수: 2 (최근 30일)
My code is as below:
f=1:1000:1000000000;
t1=1/0.4521;
t2=1/0.4908;
t3=1/0.61;
t4=1/1;
for i=1:1000:1000000000
z1(i)=(3.68*10^(-7)*(t1)^(1/2)*(2*3.14*f(i))^0.5);
z2(i)=(3.68*10^(-7)*(t2)^(1/2)*(2*3.14*f(i))^0.5);
z3(i)=(3.68*10^(-7)*(t3)^(1/2)*(2*3.14*f(i))^0.5);
z4(i)=(3.68*10^(-7)*(t4)^(1/2)*(2*3.14*f(i))^0.5);
end
loglog(f,z1,'r',f,z2,'b',f,z3,'g',f,z4,'k');
xlabel('Frequency in Hz');
ylabel('Impedance in ohm');
Error is as below:
Error in ==> he_impe at 3
f=1:1000000000;
??? Attempted to access f(1e+006); index out of bounds because
numel(f)=1000000.
Error in ==> he_impe at 9
z1(i)=(3.68*10^(-7)*(t1)^(1/2)*(2*3.14*f(i))^0.5);
  댓글 수: 1
Jan
Jan 2012년 4월 28일
"3.68*10^(-7)" is processed much more efficient by "3.68e-7". SQRT is much faster than "^(1/2)".

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 4월 28일
Yes, that makes sense. 1:1000:1E9 has 1E9/1000 elements in it, but you try to access those elements at indexes as high as 1E9.
I would suggest to you:
for i=1:length(f)

추가 답변 (1개)

Jan
Jan 2012년 4월 28일
You can replace the loop:
z1 = 3.68e-7 * sqrt(t1 * 2 * 3.14 * f);
z2 = 3.68e-7 * sqrt(t2 * 2 * 3.14 * f);
z3 = 3.68e-7 * sqrt(t3 * 2 * 3.14 * f);
z4 = 3.68e-7 * sqrt(t4 * 2 * 3.14 * f);

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by