Showing posts with label Matlab basics. Show all posts
Showing posts with label Matlab basics. Show all posts

Monday, 11 August 2014

New Matlab course for Electrical and Electronics Engineers Duration 1 month


Matlab is widely used in all areas of applied mathematics in education and research. Matlab software is built up around vectors and matrices. This makes the software particularly useful for linear algebra but it is also a great tool for solving algebraic and differential equations and for numerical integration. Matlab has powerful graphic tools and can produce nice pictures in both 2D and 3D. Matlab also has some tool boxes useful for signal processing, image processing, etc. This course of 1 month duration is exclusively tailor made to meet the requirement os electrical, electronics and power system engineers. It is described the application the MatLabTM software in analysis and simulations of transient phenomena in transmission lines. Using the characteristics of this software, transmission lines are easily modeled as a mono-phase circuit. Transient simulations are also easily carried out. For these applications, it is used basic and simple tools of the MatLabTM software. So, this software improves the analysis of the proposed problem, because it is possible to obtain several types of the graphic results that are not available in the specific programs for transient analysis like the EMTP programs. So, it is possible to analyze the resistance and inductance values that depend on the frequency when it is considered detailed transmission line models. It is possible to analyze the application of different numeric methods for solving the differential state equations by numeric integration routines. On the other hand, with a simple model of the transmission lines and the MatLabTM software, it is possible to develop a routine that is used by undergraduate students, making easy the learning about important concepts as wave propagation, transient phenomena and transmission lines. This routine can be modified, introducing elements that are able to consider the frequency influence in the transmission line parameters. These parameters have their characteristics distributed along the line and this is considered in the mentioned routine.

Thursday, 24 October 2013

To plot V(t) and I(t) for an electrical RL circuit: Matlab Program


Numerical # 1 For an R-L circuit, the voltage v(t ) and current i(t ) are given as V(t) = 10cos(377t); i(t) = 5 cos(377t+60˚) Sketch v(t ) and i(t ) for t = 0 to 20 milliseconds. Solution MATLAB Script % RL circuit % current i(t) and voltage v(t) are generated; t is time t = 0:1e-3:20e-3; v = 10*cos(377*t); a_rad = (60*pi/180); % angle in radians i = 5*cos(377*t + a_rad); plot(t,v,'r*',t,i,'go') title('Voltage and Current of an RL circuit') xlabel('Sec') ylabel('Voltage(V) and Current(mA)') text(0.003, 1.5, 'v(t)'); text(0.009,2, 'i(t)') The output of program can be seen in figure below

Thursday, 29 August 2013

inline and ezplot functions elaborated

You can simply plot the function by using inline and ezplot command in the following way:





> fcn = inline('exp(-0.2*t).*sin(200*t+pi/20)','t')

fcn =

     Inline function:
     fcn(t) = exp(-0.2*t).*sin(200*t+pi/20)

>> fcn(0:10e-4:0.4);

>> ezplot(fcn)

time t array can be varied and again a new c=plot can be achieved

Wednesday, 28 August 2013

Matlab code for switch case function: Conversion of units of length

% Matlab program to demonstrate switch case function

x = 3.0;               % numeric variable for length
units = 'cm';         % string variable for unit
switch     units
    case    {'in','inch'}      % case 1 if unit is inch
           y = 2.54*x;        % converts to centimeters
          disp  ([num2str(x)  '   ' units ' converted to cm is :' num2str(y)])
            %  disp is used to print pretty in the command window
            %  in the above a string vector is being printed
     case   {'m','meter'}    % case 2 unit is meter
           y = x*100;        % converts to centimeters
           disp  ([num2str(x)  '   ' units ' converted to cm is :' num2str(y)])
     case   { 'millimeter','mm'} % case 3 unit is millimeter
           y = x/10;
          disp  ([num2str(x)  '   ' units ' converted to cm is :' num2str(y)])
    case {'cm','centimeter'}     % case 4 unit is centimeter
          y = x;
          disp  ([num2str(x)  '   ' units ' converted to cm is :' num2str(y)])
    otherwise                    % for all other cases
         disp    (['unknown units:' units])
         y = nan;  % not a number
end

Tuesday, 6 August 2013

Useful MATLAB formats for data display

>> angle  = [pi/4 (180/pi)*(pi/4)]
angle =  0.7854   45.0000

>> format short
>> angle
angle =  0.7854   45.0000

>> format short e
>> angle
angle = 7.8540e-001  4.5000e+001

>> format short g
>> angle
angle = 0.7854           45

>> format long
>> angle
angle = 0.78539816339745  45.00000000000000

>> format long e
>> angle
angle = 7.853981633974483e-001    4.500000000000000e+001

>> format long g
>> angle
angle = 0.785398163397448                        45

>> format bank
>> angle
angle =  0.79         45.00

>> format rat
>> angle
angle = 355/452         45      

>> format hex
>> angle
angle = 3fe921fb54442d18   4046800000000000

>> format compact
>> angle

angle =     0.7854   45.0000

Monday, 5 August 2013

Matlab code to verify maximum power transfer theorem

%Program to plot power versus load resistance plot to verify maximum
%power transfer theorem

clc;
clear all;

Vm = 340;
Vrms = 340 / sqrt(2);
Rth = 100;
RL  = 50:1:200;
IL = Vrms./(Rth + RL);
PL = IL.^2 .* RL;

plot(RL,PL,'k*')
hold on 
title('\bf Maximum Power Transfer Theorem','FontSize',14);
xlabel('\bf Load Resistance','FontSize',10);
ylabel('\bf Power transferred to load','Fontsize',10);
gtext('Rth = RL = 100')
legend('PL')
grid on


Sunday, 4 August 2013

Matlab code for three phase voltage source including all labels and legends

% Program to develop user defined Three Phase voltage source
clc;
clear all;

Vm = input('Enter Peak Magnitude Required in volts: ');
f = input('Enter Supply frequency in Hz: ');
w = 2 * pi * f; % Angular frequency in rad/sec
time = input('Enter time in sec upto which output is required: ');
t = 0:10e-6:time;
First_phase = Vm * sin(w * t);
Second_phase = Vm * sin(w * t + 120);
Third_phase = Vm * sin(w * t - 120);
subplot(3,1,1),plot(t,First_phase,'r-')
axis([0 time -Vm Vm])
title('\bfFirst Phase Voltage');
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in volts');
legend('R-Phase 1')
subplot(3,1,2),plot(t,Second_phase,'y-')
axis([0 time -Vm Vm])
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in volts');
title('\bfSecond Phase voltage');
legend('Y-Phase 2')
subplot(3,1,3),plot(t,Third_phase,'b-')
axis([0 time -Vm Vm])
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in volts');
title('\bfThird Phase Voltage ');
legend('B-Phase 3')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Enter Peak Magnitude Required in volts: 340
%Enter Supply frequency in Hz: 50
%Enter time in sec upto which output is required: 0.06
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%% End of the program %%%%%%%%%%%%%%%%%%%%%%%%

Monday, 25 February 2013

Matlab code for famous Mexican hat

code


% program to plot Maxican hat

[x,y] = meshgrid(-8:0.5:8);
r = sqrt(x.^2+y.^2)+eps;
z = sin(r)./r;
surfc(z), shading flat
axis off

Thursday, 26 July 2012

Error while executing a MATLAB code!!!

In MATLAB there are four types of errors:

1.  Syntax Error
2. Runtime Error
3. Logical Error
4. Numerical Error

Of these Syntax error in encountered the most by begineers and Logical and nuemerical by experencied users.
Try to find out more about these errors.

Wednesday, 25 July 2012

Few Tips for MATLAB programming

1. The only thing worse than getting an error message is not getting an error message.

2. MATLAB uses the IEEE double-precision floating-point format,
which provides about 15 significant digits of precision (in base 10). Leading
and trailing zeros don’t count as “significant” digits, so MATLAB can represent
large and small numbers with the same precision.

3. A comment is the part of a program that provides additional information about the
program, but does not affect its execution.



4. You must always be 100% sure that the code you are running is the
     code you think you are running.

5. Error messages tell you where the problem was discovered, not where
    it was caused.

6. The worst bugs aren’t in your code; they are in your head.

7. The best way to avoid a bug is to make it impossible.

Tuesday, 24 July 2012

Elementry mathematical computations using MATLAB? Try these five:

1.      Perform the following calculations in MATLAB, taking variables x = 100 and y = 50:

a.       z = x/y;  b. u = x*y; c. v = x+y; d. r  = √x/y; e. t = √x*y; f. q = x sin(5y).

2.      Taking x = 2.10101 and y = 4.3457, estimate the following expressions in MATLAB:
a.       5x/3y;  b. 45x-8/y-7;  c. x-3-y-4;  d. x6.7/(4x+y-3.1)2
     
3.      Using MATLAB calculate:

a.       e(-1.3)3+ 16 sin(40π); b. π log 21 + 5√291; c. sin2 16π/40 + cos2 16π/40;

d. tan (4π/5)2; e. tan-10.52.

4.      Take variables x = 6 + 7i and y = -5+ 3i. Estimate with the help of MATLAB:

a.       x + y;     b. xy;      c. x/y;          d. x2 + y2.

5.      Construct a circuit for analyzing the waveform of a sine wave source using a scope in SIMULINK? Take the source frequency as 50 Hz, 60 Hz, 80 Hz & 100 Hz and verify it on the scope by viewing it’s time period?