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

回答 (1 件)

the cyclist
the cyclist 2015 年 5 月 6 日
編集済み: the cyclist 2015 年 5 月 6 日

0 投票

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 件のコメント

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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGeneral Applications についてさらに検索

質問済み:

2015 年 5 月 6 日

コメント済み:

2015 年 5 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by