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

Click For Summary
SUMMARY

The forum discussion addresses a discrepancy in MATLAB regarding the maximum value of Rf in a graph versus the output from the max() function. The user encountered a situation where the graph indicated a maximum Vo difference of approximately 10,000 for Rf, while MATLAB reported Rf at (Vo)max as 100,001. The resolution clarified that the max() function returns an index into the original Rf array, not the direct value, explaining the confusion. The correct interpretation shows that Rf(100001) corresponds to 10,000 ohms, aligning with the expected results.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of symbolic variables in MATLAB
  • Knowledge of plotting in MATLAB
  • Basic concepts of voltage and resistance in electrical circuits
NEXT STEPS
  • Explore MATLAB's max() function and its return values
  • Learn about symbolic computation in MATLAB
  • Investigate MATLAB plotting techniques for data visualization
  • Study the relationship between voltage, resistance, and current in circuits
USEFUL FOR

This discussion is beneficial for MATLAB users, electrical engineers, and students who are analyzing voltage differences in circuit simulations and need to understand data indexing in MATLAB.

babayevdavid
Messages
17
Reaction score
0
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)
 
Physics news on Phys.org
There is no issue here.

Rf has 1,000,001 elements, as does Vo_difference.

The maximum of Vo_difference is 0.02, occurring at index 100,001. This means Vo_difference(100001) = 0.02.

The part you missed is that Rf(100001) = 10000 as expected. That is, the Rf you printed with max() gives you an index _into_ the original Rf, not a direct value of Rf.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K