Variable integration limits for plotting

Hello, I would like to know how I can set "alpha" as a variable between 0 and 2*pi, and plot "Pload" against "alpha". I have tried to set alpha as linspace(0,2*pi) but the integral requires a scalar for its limits. That is the limit of my knowledge of matlab! I have checked other peoples answers, but can't find the method to fit my specific question.
For those interested, the script is for a simple triac controlling a lamp, where "alpha" is the firing angle of the triac. I have set alpha to pi/3 to obtain the power in the load "Pload" at that specific angle, by want to apply this to all angles from 0 - 2*pi.
Any help appreciated. Chris
Code :
Pbulb = 100;
Vsource = 230;
Vpeak = Vsource*sqrt(2);
T = 2*pi;
alpha = pi/3;
Ifull = Pbulb/Vsource;
Rbulb = Vsource/Ifull;
P = @(x) (((Vpeak*sin(x)).^2)/Rbulb);
Pload = (1/T)*(((integral((P),alpha,(3*alpha))))+(integral((P),(4*alpha),(6*alpha))))

Answers (1)

the cyclist
the cyclist on 6 May 2015
Edited: the cyclist on 6 May 2015
Use the linspace command to define the range of possible alpha values, then use a loop to calculate Pload for each value of alpha:
Pbulb = 100;
Vsource = 230;
Vpeak = Vsource*sqrt(2);
T = 2*pi;
alphaRange = linspace(0,2*pi);
numberAlphas = numel(alphaRange);
Pload = zeros(1,numberAlphas);
for na = 1:numberAlphas
alpha = alphaRange(na);
Ifull = Pbulb/Vsource;
Rbulb = Vsource/Ifull;
P = @(x) (((Vpeak*sin(x)).^2)/Rbulb);
Pload(na) = (1/T)*(((integral((P),alpha,(3*alpha))))+(integral((P),(4*alpha),(6*alpha))));
end
figure
plot(alphaRange,Pload)

2 Comments

Fantastic, thank you very much. Now I shall teach myself more about For loops!
Chris
The best form of thanks is accepting the answer, signifying its usefulness to you (and potentially others).

Sign in to comment.

Categories

Find more on General Applications in Help Center and File Exchange

Asked:

on 6 May 2015

Commented:

on 6 May 2015

Community Treasure Hunt

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

Start Hunting!