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))))

Risposte (1)

the cyclist
the cyclist il 6 Mag 2015
Modificato: the cyclist il 6 Mag 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 Commenti

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).

Accedi per commentare.

Categorie

Scopri di più su General Applications in Centro assistenza e File Exchange

Commentato:

il 6 Mag 2015

Community Treasure Hunt

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

Start Hunting!

Translated by