Calculate and plot real and reactive power matlab

Click For Summary
SUMMARY

The discussion focuses on creating a MATLAB function to compute and plot real and reactive power based on a given complex impedance. The function, named Compute_Power_Real_Reactive, takes impedance and either voltage or current as inputs, and it should generate four plots for the specified ranges. The user encountered an error related to matrix dimensions, which was resolved by using element-wise operations with the .* operator instead of the standard multiplication operator.

PREREQUISITES
  • Understanding of complex impedance in electrical engineering
  • Familiarity with MATLAB programming and syntax
  • Knowledge of real and reactive power calculations
  • Experience with plotting functions in MATLAB
NEXT STEPS
  • Learn about MATLAB element-wise operations and their applications
  • Explore MATLAB plotting functions for visualizing complex data
  • Study the concepts of real and reactive power in AC circuits
  • Investigate advanced MATLAB functions for handling complex numbers
USEFUL FOR

Electrical engineering students, MATLAB programmers, and anyone interested in power analysis in AC circuits will benefit from this discussion.

DODGEVIPER13
Messages
668
Reaction score
0

Homework Statement


Write a Matlab function to compute and plot real and reactive power consumed (or
supplied) by a known impedance (the value of complex impedance should be used as the function’s input) as a function of either current or voltage (use a character: V or I as a second input) for a predefined range of 0-200 V or 0-10 A. Your function must report the impedance value in the plot title. Both, real and reactive powers should be plotted on the same axes. Verify functionality of your module for 300+j100 Ω and 100-j100 Ω impedances. Plot the power both
vs. voltage and current (total of four separate graphs).



Homework Equations





The Attempt at a Solution


function[Real,Reactive]=Compute_Power_Real_Reactive(impedance,V)


I=V/abs(impedance);
theta=atan(imag(impedance)/real(impedance));

P=V*I*cos(theta);
Q=V*I*sin(theta);

disp(P);
disp(Q);
end

This is my code so far this is what I get:

>> Compute_Power_Real_Reactive(300+100i,1:50:200)
? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> Compute_Power_Real_Reactive at 7
P=V*I*cos(theta);

I cannot figure out why this doesn't work
 
Physics news on Phys.org
in MATLAB everything is matrix based. so if you do A/B, that is matrix division of A and B.

if you do A./B, that is element by element division of A and B.

so short answer, your code should look like this

P=V.*I*cos(theta);
Q=V.*I*sin(theta);
 
Thanks I figured out what I was doing wrong turns out I was right on some of it but needs quite a bit more code to do
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
7
Views
6K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K