Making a new function with code
Show older comments
Hi guys,
im trying to make a new function called poweroutput with code that has been used before in different task, im confused on how i would convert this code into a function so it can be used for a differnet task, in the new function i should be able to change the inputs of the variables.
1 Comment
Original question by Sebastion Sunny retrieved from Google Cache:
Making a new function with code
Hi guys,
im trying to make a new function called poweroutput with code that has been used before in different task, im confused on how i would convert this code into a function so it can be used for a differnet task, in the new function i should be able to change the inputs of the variables Windspeeds,Cd and deltaT:
clear
close all
%vairables defined
Cp = 0.335;
Ct = 0.042;
Vrated = 11.5; %m/s
Vcutin = 3; %m/s
Vcutout = 25; %m/s
D = 171;
k = 6e6;
j = 100e5;
%Create wind,time and rotational speed variables
deltaT = 0.01;
time = 0:deltaT:300;
WindSpeeds = linspace(0,30,length(time));%m/s
%preallocation
rotorTorque = zeros(length(WindSpeeds),1); %Nm
turbinePower = zeros(length(WindSpeeds),1);
generatorTorque = zeros(length(WindSpeeds),1);
omegaRotor = zeros(length(WindSpeeds),1);
%eulers method
for i = 2:length(time)
rotorTorque(i) = windTurbineRotorModel(WindSpeeds(i),Ct,D,Vcutout,Vrated,Vcutin);
omegaRotor(i) = omegaRotor(i-1)+deltaT*(rotorTorque(i)-generatorTorque(i-1)-(Cd*(omegaRotor)))/j;
turbinePower(i) = omegaRotor(i)*rotorTorque(i);
generatorTorque(i) = k * omegaRotor(i).^2;
end
figure;
plot(WindSpeeds,turbinePower/1000)
ylabel('TurbinePower kW')
hold on
yyaxis right
plot(WindSpeeds,generatorTorque/1000)
hold on
plot(WindSpeeds,rotorTorque/1000)
Thank you
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!