Find two x values for one y value

1 回表示 (過去 30 日間)
Bartosz Pasek
Bartosz Pasek 2021 年 5 月 28 日
回答済み: Jan 2021 年 5 月 28 日
I have a function where I need to know values of f for 0.707*max(WI) value. I tried this code, but found only one value:
C=1*10^(-4);
L=3*10^(-1);
R=100
N2=100;
frez=1/(2*pi*sqrt(L*C)) %f value for Imax(theory of RLC circles)
WI=zeros(N2+1,1);
f=zeros(N2+1,1);
for n=0:N2
omega=2*pi*n;
I=1/(sqrt(R^2+(omega*L-(1/(omega*C)))^2));
WI(n+1)=I;
fcz=n;
f(n+1)=fcz;
end
plot(f,WI)
Imax=max(WI)
Igr=0.707*max(WI) %value that I searched for
[~, index] = min(abs(WI - 0.707*max(WI))); %trying to find f values for Igr but only one show up(should be two)
fgr=f(index)

採用された回答

Star Strider
Star Strider 2021 年 5 月 28 日
C=1*10^(-4);
L=3*10^(-1);
R=100
R = 100
N2=100;
frez=1/(2*pi*sqrt(L*C)) %f value for Imax(theory of RLC circles)
frez = 29.0576
WI=zeros(N2+1,1);
f=zeros(N2+1,1);
for n=0:N2
omega=2*pi*n;
I=1/(sqrt(R^2+(omega*L-(1/(omega*C)))^2));
WI(n+1)=I;
fcz=n;
f(n+1)=fcz;
end
[WImax,idx] = max(WI) % Find Maximum & Index
WImax = 0.0100
idx = 30
idxv = {1:idx; idx:numel(f)} % Create Index Vectors
idxv = 2×1 cell array
{[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30]} {[30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101]}
for k = 1:2
xval(k) = interp1(WI(idxv{k}),f(idxv{k}), WImax/sqrt(2)) % Interpolate To Fine X-Values
end
xval = 12.8235
xval = 1×2
12.8235 65.8711
plot(f,WI)
hold on
plot(xval, [1 1]*WImax/sqrt(2), 'rs') % Plot Desired Points
hold off
Imax=max(WI)
Imax = 0.0100
Igr=0.707*max(WI) %value that I searched for
Igr = 0.0071
[~, index] = min(abs(WI - 0.707*max(WI))); %trying to find f values for Igr but only one show up(should be two)
fgr=f(index)
fgr = 66
.
  2 件のコメント
Bartosz Pasek
Bartosz Pasek 2021 年 5 月 28 日
Thank You a lot
Star Strider
Star Strider 2021 年 5 月 28 日
As always, my pleasure!

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

その他の回答 (1 件)

Jan
Jan 2021 年 5 月 28 日
tmp = abs(WI - 0.707*max(WI));
minValue = min(tmp);
index = (tmp == minValue);
fgr = f(index)
For numerical values it is unlikely that there are no rounding artifacts. Searching for tmp==minValue is critical. Prefer to use a tolerance of a matching size instead.

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by