Help with MATLAB code; discrepancy between graph's max and Matlab's max

14 ビュー (過去 30 日間)
David
David 2014 年 2 月 16 日
回答済み: David 2014 年 2 月 16 日
Hi,
For some reason, when I run this MATLAB code, I'm getting what looks like about 10,000 for Rf for the largest Vo on the graph, but matlab is giving me Rf at (Vo)max as 100,001
Any ideas?
clc; clear; close all;
syms Rf
Rf = 0:0.1:100000;
VRt25 = 18.*(10000)./(10000 + Rf); VRf25 = 18.*(Rf)./(10000 + Rf);
VRt2505 = 18.*(9977.81)./(9977.81 + Rf); VRf2505 = 18.*(Rf)./(9977.81 + Rf);
V_difference25 = abs(VRt25 - VRf25);
V_difference2505 = abs(VRt2505 - VRf2505);
Vo_difference = abs(V_difference25 - V_difference2505);
figure;
plot(Rf,Vo_difference)
title('Voltage Difference Vo vs. Rf')
ylabel('Vo Difference [V]')
xlabel('Rf [ohms]')
hold on
%Maximum Vo Difference
[Vo_difference_max,Rf] = max(Vo_difference)
Thank you all!

採用された回答

Image Analyst
Image Analyst 2014 年 2 月 16 日
The max() function returns the index of Vo_difference, not Rf directly. Plus Rf starts at 0 not 1. Try this:
Rf = 0 : 0.1 : 100000;
VRt25 = 18.*(10000)./(10000 + Rf); VRf25 = 18.*(Rf)./(10000 + Rf);
VRt2505 = 18.*(9977.81)./(9977.81 + Rf); VRf2505 = 18.*(Rf)./(9977.81 + Rf);
V_difference25 = abs(VRt25 - VRf25);
V_difference2505 = abs(VRt2505 - VRf2505);
Vo_difference = abs(V_difference25 - V_difference2505);
figure;
plot(Rf,Vo_difference)
title('Voltage Difference Vo vs. Rf')
ylabel('Vo Difference [V]')
xlabel('Rf [ohms]')
hold on
%Maximum Vo Difference
[Vo_difference_max, indexAtMax] = max(Vo_difference)
RfAtMax = Rf(indexAtMax)
message = sprintf('The Rf at max Vo = %f.', RfAtMax);
helpdlg(message);

その他の回答 (1 件)

David
David 2014 年 2 月 16 日
Ah yes, I remember that little detail now. Had me baffled a few semesters ago as well. That helped. Thank you very much!

カテゴリ

Help Center および File ExchangeSignal Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by