# Matlab and Power

1. Feb 14, 2006

### seang

Hi;

In this problem we're supposed to use matlab to make plots of power vs. a load resistance, with a load reactance held constant. I'm pretty new to matlab, but moderately experienced in programming in general. I think the meat of program is in red below; we're supposed to fill up the matrix with the values to be plotted (I think). I'm not really sure if this is how to do about things, or what my professor wants. Anyone got any ideas?

Code (Text):
%   This program evaluates the average power delivered to
%   a load ZL = RL + j XL from a source circuit.
%   The source circuit is represented by:
%   (1) A Thevenin equivalent voltage VT, and
%   (2) A Thevenin equivalent impedance ZT = RT + j XT.
%

%   It is a good practice to start a MatLab program by clearing/closing
%   any variables, functions, and figures that may have been used
%   by previous runs of this program or other programs
clear all;
close all;

%Thevenin voltage magnitude of the source
VT = 100;

%Thevenin resistance and reactance of the source
RT = 20;
XT = 20;

%
%   PLEASE NOTE THAT YOU MIGHT BE MORE
%   COMFORTABLE WITH EVALUATING THE POWER
%   USING 1-D FUNCTIONS/VECTORS. THAT IS PERFECTLY FINE.
%   THE APPROACH USED BELOW MAY BE A BIT ADVANCED
%   FOR THOSE WHO ARE NOT VERY FAMILIAR WITH MATLAB.
%   PLEASE USE ANY APPROACH THAT YOU FEEL COMFORTABLE WITH.
%

%   There are several MatLab methods that can be used to
%   evaluate the average power P.
%   Here, we first treat the average power P as
%   a 2-D function of both RL & XL : P(RL,XL).
%   Then, we evaluate/plot the desired 1-D function,
%   such as P(RL) for a given XL, or P(XL) for a given RL.
%
%
%   We first treat both RL and XL as variables.
%   Variable load resistance and reactance.
%
%   AFETR YOU RUN THE PROGRAM SUCCESSFULLY, YOU COULD/SHOULD
%   INCREASE THE RESOLUTION FOR SAMPLING RL AND XL.
%   FOR EXAMPLE, YOU COULD USE 0.1 INSTEAD OF 1.
%
RL = [0:1:100];
XL = [-100:1:100];

Num_RL=length(RL);
Num_XL=length(XL);

%
%   Evaluating the average power delivered to the load.
%   On average, the power only goes to the resistance,
%   and we use equation 8-34 to evaluate the power P(RL,XL).
%   Below, we use a 2-D matrix to evaluate and store the
%   2-D function P(RL,XL).
%
[COLOR="Red"]for i=1:Num_RL,
for j=1:Num_XL,
P(i,j) =
end
end[/COLOR]

%
%   Part (A):
%
%   In this part, we are given the load reactance XL,
%   and we are asked to plot the average power P as a function
%   of the remainder unknown variable, which is the load
%   resistance RL. This represents the function P(RL).

%
%   Identifying the indices that correspond to the desired values of XL.
%
XL_minus20_index = find(XL==-20);
% REPEAT for XL=20

%
%   Find the maximum values of the average power at the desired
%   XL values. We store these maximum values in P_max_XL_xxxx.
%   We also can evaluate the index of RL that gives a maximum value.
%

[P_max_XL_minus20, RL_index_for_XL_minus20] = max(P(:,XL_minus20_index));
% REPEAT for XL=20

%
%   Find the values of the load resistance RL that gives these
%   maximum average power values.
%
RL_value_for_XL_minus20 = RL(RL_index_for_XL_minus20)
P_max_XL_minus20

% REPEAT for XL=20

%
%   Plot the two functions P(RL) for the two values of XL
%
plot(RL,P(:,XL_minus20_index),'b');
figure;
% REPEAT for XL=20