Category: Matlab
Category Archives: Matlab
initialize a MxN matrix with the same number
I would initialize a M x N matrix with the same number. Which could be the best way in terms of speed?
Es.
[2 2;
2 2
2 2]I would initialize a M x N matrix with the same number. Which could be the best way in terms of speed?
Es.
[2 2;
2 2
2 2] I would initialize a M x N matrix with the same number. Which could be the best way in terms of speed?
Es.
[2 2;
2 2
2 2] matrix MATLAB Answers — New Questions
Simulating a 2D Random Walk
How can I turn my 1D Random Walk code into a 2D Random Walk.
Heres my code for the 1D Random walk:
N = 100; % Number of steps
single_trajectory = simulateRandomWalk(N);
figure
plot(0:N, single_trajectory, ‘-o’)
title(‘1D Random Walk – Single Trajectory’)
xlabel(‘Steps’)
ylabel(‘Position’)
P_values = [50, 500, 5000, 50000, 500000];
for p_index = 1:length(P_values)
P = P_values(p_index);
final_positions = zeros(1, P);
for i = 1:P
single_trajectory = simulateRandomWalk(N);
final_positions(i) = single_trajectory(end);
end
% Plot histogram of final positions
figure
histogram(final_positions, ‘Normalization’, ‘probability’)
title([‘Histogram for P = ‘ num2str(P)])
xlabel(‘Final Position’)
ylabel(‘Probability’)
end
function trajectory = simulateRandomWalk(N)
% Initialize position
position = 0;
% Initialize trajectory array
trajectory = zeros(1, N+1);
trajectory(1) = position;
% Simulate random walk
for step = 1:N
% Generate a random number to decide left or right movement
move = randi([0, 1])*2 – 1; % -1 for left, 1 for right
% Update position
position = position + move;
% Store the current position in the trajectory array
trajectory(step+1) = position;
end
endHow can I turn my 1D Random Walk code into a 2D Random Walk.
Heres my code for the 1D Random walk:
N = 100; % Number of steps
single_trajectory = simulateRandomWalk(N);
figure
plot(0:N, single_trajectory, ‘-o’)
title(‘1D Random Walk – Single Trajectory’)
xlabel(‘Steps’)
ylabel(‘Position’)
P_values = [50, 500, 5000, 50000, 500000];
for p_index = 1:length(P_values)
P = P_values(p_index);
final_positions = zeros(1, P);
for i = 1:P
single_trajectory = simulateRandomWalk(N);
final_positions(i) = single_trajectory(end);
end
% Plot histogram of final positions
figure
histogram(final_positions, ‘Normalization’, ‘probability’)
title([‘Histogram for P = ‘ num2str(P)])
xlabel(‘Final Position’)
ylabel(‘Probability’)
end
function trajectory = simulateRandomWalk(N)
% Initialize position
position = 0;
% Initialize trajectory array
trajectory = zeros(1, N+1);
trajectory(1) = position;
% Simulate random walk
for step = 1:N
% Generate a random number to decide left or right movement
move = randi([0, 1])*2 – 1; % -1 for left, 1 for right
% Update position
position = position + move;
% Store the current position in the trajectory array
trajectory(step+1) = position;
end
end How can I turn my 1D Random Walk code into a 2D Random Walk.
Heres my code for the 1D Random walk:
N = 100; % Number of steps
single_trajectory = simulateRandomWalk(N);
figure
plot(0:N, single_trajectory, ‘-o’)
title(‘1D Random Walk – Single Trajectory’)
xlabel(‘Steps’)
ylabel(‘Position’)
P_values = [50, 500, 5000, 50000, 500000];
for p_index = 1:length(P_values)
P = P_values(p_index);
final_positions = zeros(1, P);
for i = 1:P
single_trajectory = simulateRandomWalk(N);
final_positions(i) = single_trajectory(end);
end
% Plot histogram of final positions
figure
histogram(final_positions, ‘Normalization’, ‘probability’)
title([‘Histogram for P = ‘ num2str(P)])
xlabel(‘Final Position’)
ylabel(‘Probability’)
end
function trajectory = simulateRandomWalk(N)
% Initialize position
position = 0;
% Initialize trajectory array
trajectory = zeros(1, N+1);
trajectory(1) = position;
% Simulate random walk
for step = 1:N
% Generate a random number to decide left or right movement
move = randi([0, 1])*2 – 1; % -1 for left, 1 for right
% Update position
position = position + move;
% Store the current position in the trajectory array
trajectory(step+1) = position;
end
end matlab MATLAB Answers — New Questions
Simulating a 2D Random Walk
How can I turn my 1D Random Walk code into a 2D Random Walk.
Heres my code for the 1D Random walk:
N = 100; % Number of steps
single_trajectory = simulateRandomWalk(N);
figure
plot(0:N, single_trajectory, ‘-o’)
title(‘1D Random Walk – Single Trajectory’)
xlabel(‘Steps’)
ylabel(‘Position’)
P_values = [50, 500, 5000, 50000, 500000];
for p_index = 1:length(P_values)
P = P_values(p_index);
final_positions = zeros(1, P);
for i = 1:P
single_trajectory = simulateRandomWalk(N);
final_positions(i) = single_trajectory(end);
end
% Plot histogram of final positions
figure
histogram(final_positions, ‘Normalization’, ‘probability’)
title([‘Histogram for P = ‘ num2str(P)])
xlabel(‘Final Position’)
ylabel(‘Probability’)
end
function trajectory = simulateRandomWalk(N)
% Initialize position
position = 0;
% Initialize trajectory array
trajectory = zeros(1, N+1);
trajectory(1) = position;
% Simulate random walk
for step = 1:N
% Generate a random number to decide left or right movement
move = randi([0, 1])*2 – 1; % -1 for left, 1 for right
% Update position
position = position + move;
% Store the current position in the trajectory array
trajectory(step+1) = position;
end
endHow can I turn my 1D Random Walk code into a 2D Random Walk.
Heres my code for the 1D Random walk:
N = 100; % Number of steps
single_trajectory = simulateRandomWalk(N);
figure
plot(0:N, single_trajectory, ‘-o’)
title(‘1D Random Walk – Single Trajectory’)
xlabel(‘Steps’)
ylabel(‘Position’)
P_values = [50, 500, 5000, 50000, 500000];
for p_index = 1:length(P_values)
P = P_values(p_index);
final_positions = zeros(1, P);
for i = 1:P
single_trajectory = simulateRandomWalk(N);
final_positions(i) = single_trajectory(end);
end
% Plot histogram of final positions
figure
histogram(final_positions, ‘Normalization’, ‘probability’)
title([‘Histogram for P = ‘ num2str(P)])
xlabel(‘Final Position’)
ylabel(‘Probability’)
end
function trajectory = simulateRandomWalk(N)
% Initialize position
position = 0;
% Initialize trajectory array
trajectory = zeros(1, N+1);
trajectory(1) = position;
% Simulate random walk
for step = 1:N
% Generate a random number to decide left or right movement
move = randi([0, 1])*2 – 1; % -1 for left, 1 for right
% Update position
position = position + move;
% Store the current position in the trajectory array
trajectory(step+1) = position;
end
end How can I turn my 1D Random Walk code into a 2D Random Walk.
Heres my code for the 1D Random walk:
N = 100; % Number of steps
single_trajectory = simulateRandomWalk(N);
figure
plot(0:N, single_trajectory, ‘-o’)
title(‘1D Random Walk – Single Trajectory’)
xlabel(‘Steps’)
ylabel(‘Position’)
P_values = [50, 500, 5000, 50000, 500000];
for p_index = 1:length(P_values)
P = P_values(p_index);
final_positions = zeros(1, P);
for i = 1:P
single_trajectory = simulateRandomWalk(N);
final_positions(i) = single_trajectory(end);
end
% Plot histogram of final positions
figure
histogram(final_positions, ‘Normalization’, ‘probability’)
title([‘Histogram for P = ‘ num2str(P)])
xlabel(‘Final Position’)
ylabel(‘Probability’)
end
function trajectory = simulateRandomWalk(N)
% Initialize position
position = 0;
% Initialize trajectory array
trajectory = zeros(1, N+1);
trajectory(1) = position;
% Simulate random walk
for step = 1:N
% Generate a random number to decide left or right movement
move = randi([0, 1])*2 – 1; % -1 for left, 1 for right
% Update position
position = position + move;
% Store the current position in the trajectory array
trajectory(step+1) = position;
end
end matlab MATLAB Answers — New Questions
How to get a plot out of a .csv data from a sensor?
Hello Community,
I have a problem with creating a plot from the .csv-data which I created by a distance sensor. I want to have the measure time in the x-axis and the distance on the y-axis. Could anyone help me for coding?
Thank you for helping me.Hello Community,
I have a problem with creating a plot from the .csv-data which I created by a distance sensor. I want to have the measure time in the x-axis and the distance on the y-axis. Could anyone help me for coding?
Thank you for helping me. Hello Community,
I have a problem with creating a plot from the .csv-data which I created by a distance sensor. I want to have the measure time in the x-axis and the distance on the y-axis. Could anyone help me for coding?
Thank you for helping me. plotting, csv MATLAB Answers — New Questions
How to get a plot out of a .csv data from a sensor?
Hello Community,
I have a problem with creating a plot from the .csv-data which I created by a distance sensor. I want to have the measure time in the x-axis and the distance on the y-axis. Could anyone help me for coding?
Thank you for helping me.Hello Community,
I have a problem with creating a plot from the .csv-data which I created by a distance sensor. I want to have the measure time in the x-axis and the distance on the y-axis. Could anyone help me for coding?
Thank you for helping me. Hello Community,
I have a problem with creating a plot from the .csv-data which I created by a distance sensor. I want to have the measure time in the x-axis and the distance on the y-axis. Could anyone help me for coding?
Thank you for helping me. plotting, csv MATLAB Answers — New Questions
How can I plot the following function?
alpha=0.001:0.1:5;
s=1;sb=.1;s1=sb./s;j=0.1;EZ=1;zeta0=-1;beta=1;i=(-1).^(1./2);
sigma=0.1; ur=1;k=5;b1=0.1;b2=0.1;c=0.1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k1=k.^2.*zeta0./(1+c);
T1=(1+c)./(2.*s.*(i.*alpha.^2.*j-4.*c));
T2=(4.*s.*c-i.*alpha.^2)./(1+c);
r11=(4.*s.*c+i.*alpha.^2.*(c-j.*s.*(1+c)))./(c.*(1+c));r22=alpha.^2.*s.*(4.*i.*c+alpha.^2.*j)./(c.*(1+c));
alpha11=((1./2).*(r11+(r11.^2-4.*r22).^(1./2))).^(1./2);alpha12=-((1./2).*(r11+(r11.^2-4.*r22).^(1./2))).^(1./2);
alpha22=((1./2).*(r11-(r11.^2-4.*r22).^(1./2))).^(1./2);alpha21=-((1./2).*(r11-(r11.^2-4.*r22).^(1./2))).^(1./2);
KK=-(k1.*(k.^2-s.*(4-i.*alpha.^2.*j.*c.^(-1))))./(k.^4-(r11).*k.^2+r22);
format long g
syms r
L3 = vpaintegral(r*besselk(1,alpha11*r),r,sigma,1);
w1 =2.*( -T1 .* alpha11 .* L3.*(alpha11 .^ 2 + T2));
plot(alpha,abs(w1),’-black’,’LineWidth’,1.2);
ylabel(‘$w1(r)$’,’Interpreter’,’latex’,’FontSize’,12,’FontName’,’TiemsNewRoman’,’FontWeight’,’Normal’)
xlabel(‘$alpha$’,’Interpreter’,’latex’,’FontSize’,12,’FontName’,’TiemsNewRoman’,’FontWeight’,’Normal’)
%%%%%%%%%%%alpha=0.001:0.1:5;
s=1;sb=.1;s1=sb./s;j=0.1;EZ=1;zeta0=-1;beta=1;i=(-1).^(1./2);
sigma=0.1; ur=1;k=5;b1=0.1;b2=0.1;c=0.1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k1=k.^2.*zeta0./(1+c);
T1=(1+c)./(2.*s.*(i.*alpha.^2.*j-4.*c));
T2=(4.*s.*c-i.*alpha.^2)./(1+c);
r11=(4.*s.*c+i.*alpha.^2.*(c-j.*s.*(1+c)))./(c.*(1+c));r22=alpha.^2.*s.*(4.*i.*c+alpha.^2.*j)./(c.*(1+c));
alpha11=((1./2).*(r11+(r11.^2-4.*r22).^(1./2))).^(1./2);alpha12=-((1./2).*(r11+(r11.^2-4.*r22).^(1./2))).^(1./2);
alpha22=((1./2).*(r11-(r11.^2-4.*r22).^(1./2))).^(1./2);alpha21=-((1./2).*(r11-(r11.^2-4.*r22).^(1./2))).^(1./2);
KK=-(k1.*(k.^2-s.*(4-i.*alpha.^2.*j.*c.^(-1))))./(k.^4-(r11).*k.^2+r22);
format long g
syms r
L3 = vpaintegral(r*besselk(1,alpha11*r),r,sigma,1);
w1 =2.*( -T1 .* alpha11 .* L3.*(alpha11 .^ 2 + T2));
plot(alpha,abs(w1),’-black’,’LineWidth’,1.2);
ylabel(‘$w1(r)$’,’Interpreter’,’latex’,’FontSize’,12,’FontName’,’TiemsNewRoman’,’FontWeight’,’Normal’)
xlabel(‘$alpha$’,’Interpreter’,’latex’,’FontSize’,12,’FontName’,’TiemsNewRoman’,’FontWeight’,’Normal’)
%%%%%%%%%%% alpha=0.001:0.1:5;
s=1;sb=.1;s1=sb./s;j=0.1;EZ=1;zeta0=-1;beta=1;i=(-1).^(1./2);
sigma=0.1; ur=1;k=5;b1=0.1;b2=0.1;c=0.1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k1=k.^2.*zeta0./(1+c);
T1=(1+c)./(2.*s.*(i.*alpha.^2.*j-4.*c));
T2=(4.*s.*c-i.*alpha.^2)./(1+c);
r11=(4.*s.*c+i.*alpha.^2.*(c-j.*s.*(1+c)))./(c.*(1+c));r22=alpha.^2.*s.*(4.*i.*c+alpha.^2.*j)./(c.*(1+c));
alpha11=((1./2).*(r11+(r11.^2-4.*r22).^(1./2))).^(1./2);alpha12=-((1./2).*(r11+(r11.^2-4.*r22).^(1./2))).^(1./2);
alpha22=((1./2).*(r11-(r11.^2-4.*r22).^(1./2))).^(1./2);alpha21=-((1./2).*(r11-(r11.^2-4.*r22).^(1./2))).^(1./2);
KK=-(k1.*(k.^2-s.*(4-i.*alpha.^2.*j.*c.^(-1))))./(k.^4-(r11).*k.^2+r22);
format long g
syms r
L3 = vpaintegral(r*besselk(1,alpha11*r),r,sigma,1);
w1 =2.*( -T1 .* alpha11 .* L3.*(alpha11 .^ 2 + T2));
plot(alpha,abs(w1),’-black’,’LineWidth’,1.2);
ylabel(‘$w1(r)$’,’Interpreter’,’latex’,’FontSize’,12,’FontName’,’TiemsNewRoman’,’FontWeight’,’Normal’)
xlabel(‘$alpha$’,’Interpreter’,’latex’,’FontSize’,12,’FontName’,’TiemsNewRoman’,’FontWeight’,’Normal’)
%%%%%%%%%%% plot function MATLAB Answers — New Questions
How to add vertical line in z direction in YZ view meshplot?
I have a 2D matrix that I plot in meshplot in XY and YZ view. For the YZ view I want to overlay a vertical line centered on the 0 of the Y axis.I need something similar to yline(0) that will be viewable in YZ view of a mesh plot.
Right now I "solved" it using annotation by adding a line annotation, but this solution is not good enough for me, cause sometime I have a figure with several subplots, and since the annotation position are in relative to the figure, and not the axis, it’s too much of a hassle to calculate where to place the line annotation for each subplot
Below is an image of what I’m trying to achive in code:I have a 2D matrix that I plot in meshplot in XY and YZ view. For the YZ view I want to overlay a vertical line centered on the 0 of the Y axis.I need something similar to yline(0) that will be viewable in YZ view of a mesh plot.
Right now I "solved" it using annotation by adding a line annotation, but this solution is not good enough for me, cause sometime I have a figure with several subplots, and since the annotation position are in relative to the figure, and not the axis, it’s too much of a hassle to calculate where to place the line annotation for each subplot
Below is an image of what I’m trying to achive in code: I have a 2D matrix that I plot in meshplot in XY and YZ view. For the YZ view I want to overlay a vertical line centered on the 0 of the Y axis.I need something similar to yline(0) that will be viewable in YZ view of a mesh plot.
Right now I "solved" it using annotation by adding a line annotation, but this solution is not good enough for me, cause sometime I have a figure with several subplots, and since the annotation position are in relative to the figure, and not the axis, it’s too much of a hassle to calculate where to place the line annotation for each subplot
Below is an image of what I’m trying to achive in code: meshplot, yzview, line, subplot MATLAB Answers — New Questions
How to add vertical line in z direction in YZ view meshplot?
I have a 2D matrix that I plot in meshplot in XY and YZ view. For the YZ view I want to overlay a vertical line centered on the 0 of the Y axis.I need something similar to yline(0) that will be viewable in YZ view of a mesh plot.
Right now I "solved" it using annotation by adding a line annotation, but this solution is not good enough for me, cause sometime I have a figure with several subplots, and since the annotation position are in relative to the figure, and not the axis, it’s too much of a hassle to calculate where to place the line annotation for each subplot
Below is an image of what I’m trying to achive in code:I have a 2D matrix that I plot in meshplot in XY and YZ view. For the YZ view I want to overlay a vertical line centered on the 0 of the Y axis.I need something similar to yline(0) that will be viewable in YZ view of a mesh plot.
Right now I "solved" it using annotation by adding a line annotation, but this solution is not good enough for me, cause sometime I have a figure with several subplots, and since the annotation position are in relative to the figure, and not the axis, it’s too much of a hassle to calculate where to place the line annotation for each subplot
Below is an image of what I’m trying to achive in code: I have a 2D matrix that I plot in meshplot in XY and YZ view. For the YZ view I want to overlay a vertical line centered on the 0 of the Y axis.I need something similar to yline(0) that will be viewable in YZ view of a mesh plot.
Right now I "solved" it using annotation by adding a line annotation, but this solution is not good enough for me, cause sometime I have a figure with several subplots, and since the annotation position are in relative to the figure, and not the axis, it’s too much of a hassle to calculate where to place the line annotation for each subplot
Below is an image of what I’m trying to achive in code: meshplot, yzview, line, subplot MATLAB Answers — New Questions
Error using integral function with anonymous function
I am trying to use the following code to calculate the values of F(i,j) which is the integral of the anonymous function that I parameterized as a function of T and lambda. I believe I vectorized it correclty. However, the error I get says that the array has incompatible sizes, which I don’t understand because the same size of array worked fine for another section of the code.
“`C1 = 3.742e8;
C2 = 1.4388e4;
SB = 1.38*10.^-23; %Boltzmann’s constant
C1 = 3.742*10^8; % First constant W-micron^4/m^2
C2 = 1.4388*10^4; %Second constant microns-K
T = [300,500,1000,2000,3000,5800]; %Temperature in Kelvins
lambda = 0.1:0.1:30;%wavelength in microns
lengthT = length(T);
length_L = length(lambda);
E = zeros(lengthT,length_L);
E_prime = zeros(lengthT,length_L);
F = zeros(lengthT,length_L);“`
“`for i = 1:lengthT
for j = 1:length_L
fun = @(T, lambda) C1./(SB.*T.^4*(lambda.^5.*(exp(C2/(lambda.*T))-1)));
F(i,j) = integral(fun(T,lambda),0,length_L);
end
end“`I am trying to use the following code to calculate the values of F(i,j) which is the integral of the anonymous function that I parameterized as a function of T and lambda. I believe I vectorized it correclty. However, the error I get says that the array has incompatible sizes, which I don’t understand because the same size of array worked fine for another section of the code.
“`C1 = 3.742e8;
C2 = 1.4388e4;
SB = 1.38*10.^-23; %Boltzmann’s constant
C1 = 3.742*10^8; % First constant W-micron^4/m^2
C2 = 1.4388*10^4; %Second constant microns-K
T = [300,500,1000,2000,3000,5800]; %Temperature in Kelvins
lambda = 0.1:0.1:30;%wavelength in microns
lengthT = length(T);
length_L = length(lambda);
E = zeros(lengthT,length_L);
E_prime = zeros(lengthT,length_L);
F = zeros(lengthT,length_L);“`
“`for i = 1:lengthT
for j = 1:length_L
fun = @(T, lambda) C1./(SB.*T.^4*(lambda.^5.*(exp(C2/(lambda.*T))-1)));
F(i,j) = integral(fun(T,lambda),0,length_L);
end
end“` I am trying to use the following code to calculate the values of F(i,j) which is the integral of the anonymous function that I parameterized as a function of T and lambda. I believe I vectorized it correclty. However, the error I get says that the array has incompatible sizes, which I don’t understand because the same size of array worked fine for another section of the code.
“`C1 = 3.742e8;
C2 = 1.4388e4;
SB = 1.38*10.^-23; %Boltzmann’s constant
C1 = 3.742*10^8; % First constant W-micron^4/m^2
C2 = 1.4388*10^4; %Second constant microns-K
T = [300,500,1000,2000,3000,5800]; %Temperature in Kelvins
lambda = 0.1:0.1:30;%wavelength in microns
lengthT = length(T);
length_L = length(lambda);
E = zeros(lengthT,length_L);
E_prime = zeros(lengthT,length_L);
F = zeros(lengthT,length_L);“`
“`for i = 1:lengthT
for j = 1:length_L
fun = @(T, lambda) C1./(SB.*T.^4*(lambda.^5.*(exp(C2/(lambda.*T))-1)));
F(i,j) = integral(fun(T,lambda),0,length_L);
end
end“` anonymous, function, parameterize, vectorize, integral, integration, error MATLAB Answers — New Questions
What is the MOD APK website?
A Mod APK site provides the modded version of an APK of original application or game. This modified version will provide you with several benefits that original version provides you through a purchase. So, you can enjoy premium versions, unlimited game currencies, or free power ups in the games through the mods.
Apk InfluxA Mod APK site provides the modded version of an APK of original application or game. This modified version will provide you with several benefits that original version provides you through a purchase. So, you can enjoy premium versions, unlimited game currencies, or free power ups in the games through the mods.
Apk Influx A Mod APK site provides the modded version of an APK of original application or game. This modified version will provide you with several benefits that original version provides you through a purchase. So, you can enjoy premium versions, unlimited game currencies, or free power ups in the games through the mods.
Apk Influx ds MATLAB Answers — New Questions
What is the MOD APK website?
A Mod APK site provides the modded version of an APK of original application or game. This modified version will provide you with several benefits that original version provides you through a purchase. So, you can enjoy premium versions, unlimited game currencies, or free power ups in the games through the mods.
Apk InfluxA Mod APK site provides the modded version of an APK of original application or game. This modified version will provide you with several benefits that original version provides you through a purchase. So, you can enjoy premium versions, unlimited game currencies, or free power ups in the games through the mods.
Apk Influx A Mod APK site provides the modded version of an APK of original application or game. This modified version will provide you with several benefits that original version provides you through a purchase. So, you can enjoy premium versions, unlimited game currencies, or free power ups in the games through the mods.
Apk Influx ds MATLAB Answers — New Questions
unable to install image processing toolkit
I am trying to install image processing toolkit ,but everytime it stops in between while installation.I am trying to install image processing toolkit ,but everytime it stops in between while installation. I am trying to install image processing toolkit ,but everytime it stops in between while installation. image processing, toolbox MATLAB Answers — New Questions
How to open new command window?
I have some codes that I have saved in comand window and I want to create a new command window. So that I don’t lose my code. Please help me.I have some codes that I have saved in comand window and I want to create a new command window. So that I don’t lose my code. Please help me. I have some codes that I have saved in comand window and I want to create a new command window. So that I don’t lose my code. Please help me. command-window MATLAB Answers — New Questions
How to open new command window?
I have some codes that I have saved in comand window and I want to create a new command window. So that I don’t lose my code. Please help me.I have some codes that I have saved in comand window and I want to create a new command window. So that I don’t lose my code. Please help me. I have some codes that I have saved in comand window and I want to create a new command window. So that I don’t lose my code. Please help me. command-window MATLAB Answers — New Questions
PPO reinforcement Learning Agent doesn’t learn
Hi, I am trying to design a reinforcement learning algorithm to perform a landing on the moon in a defined region.
The algorithm I implemented is a PPO with the environment designed in simulink. The model is designed as a continuous one. The action from RL Agent simulink block is the Thrust, the observation is the state (position and velocity). The Reward is also designed in a continuous way, with penalties outside some boundaries ("exteriorPenalty" function) and reward if inside boundaries (using exponential functions) plus some others penalties on velocities and action, properly weighted.
The model seems to work but the agent doesn’t learn as it was supposed to do. I played with PPO options to limit local minima and increase exploration to help finding optimal conditions. After lot of episodes the reward function is supposed to increase, but it varies between optimal values and the worst cases. I know that training can take lot of time due the large environment, on the other hand after a while I expect to see a better behavior. Especially if Reward values are soo high in some cases.
My questions are: how can I read in a properly way my plots of Reinforcement Learning Episode Manager? Which parameters should I change to help the agent to understand what is better? Any other comments are welcomed!
Thanks for helping!
Here my code for actor and critic generation with relative options:
actPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(50,’Name’,’fc1act’)
dropoutLayer(0.2,’Name’,’drop1act’)
layerNormalizationLayer(‘Name’,’norm1act’)
reluLayer(‘Name’,’relu1act’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmact’)
layerNormalizationLayer(‘Name’,’norm2act’)
fullyConnectedLayer(2*numAct,’Name’,’fcoutput’)
layerNormalizationLayer(‘Name’,’norm3act’)
softmaxLayer(‘Name’,’SoftactionProb’)];
obsPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(100, ‘Name’, ‘fc1obs’)
dropoutLayer(0.2,’Name’,’drop1obs’)
layerNormalizationLayer(‘Name’,’norm1obs’)
reluLayer(‘Name’,’relu1obs’)
fullyConnectedLayer(22, ‘Name’, ‘fc2obs’)
dropoutLayer(0.2,’Name’,’drop2obs’)
layerNormalizationLayer(‘Name’,’norm2obs’)
reluLayer(‘Name’,’relu2obs’)
fullyConnectedLayer(5, ‘Name’, ‘fc3obs’)
dropoutLayer(0.2,’Name’,’drop3obs’)
layerNormalizationLayer(‘Name’,’norm3obs’)
reluLayer(‘Name’,’relu3obs’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmobs’)
layerNormalizationLayer(‘Name’,’norm4obs’)
fullyConnectedLayer(1,’Name’,’fcvalue’)];
opts1 = rlRepresentationOptions("Learnrate",5e-3,"GradientThreshold",10,"UseDevice","gpu");
actor = rlStochasticActorRepresentation(actPath,obsInfo,actInfo,’Observation’,’obs’,opts1)
critic = rlValueRepresentation(obsPath,obsInfo,’Observation’,’obs’,opts1)
opts2 = rlPPOAgentOptions( "ExperienceHorizon",200,…
"SampleTIme",0.25, …
"MiniBatchSize",32, …
"EntropyLossWeight",0.5, …
"AdvantageEstimateMethod","gae", …
"GAEFactor",0.8, …
"NormalizedAdvantageMethod","current");
agent = rlPPOAgent(actor,critic,opts2)Hi, I am trying to design a reinforcement learning algorithm to perform a landing on the moon in a defined region.
The algorithm I implemented is a PPO with the environment designed in simulink. The model is designed as a continuous one. The action from RL Agent simulink block is the Thrust, the observation is the state (position and velocity). The Reward is also designed in a continuous way, with penalties outside some boundaries ("exteriorPenalty" function) and reward if inside boundaries (using exponential functions) plus some others penalties on velocities and action, properly weighted.
The model seems to work but the agent doesn’t learn as it was supposed to do. I played with PPO options to limit local minima and increase exploration to help finding optimal conditions. After lot of episodes the reward function is supposed to increase, but it varies between optimal values and the worst cases. I know that training can take lot of time due the large environment, on the other hand after a while I expect to see a better behavior. Especially if Reward values are soo high in some cases.
My questions are: how can I read in a properly way my plots of Reinforcement Learning Episode Manager? Which parameters should I change to help the agent to understand what is better? Any other comments are welcomed!
Thanks for helping!
Here my code for actor and critic generation with relative options:
actPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(50,’Name’,’fc1act’)
dropoutLayer(0.2,’Name’,’drop1act’)
layerNormalizationLayer(‘Name’,’norm1act’)
reluLayer(‘Name’,’relu1act’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmact’)
layerNormalizationLayer(‘Name’,’norm2act’)
fullyConnectedLayer(2*numAct,’Name’,’fcoutput’)
layerNormalizationLayer(‘Name’,’norm3act’)
softmaxLayer(‘Name’,’SoftactionProb’)];
obsPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(100, ‘Name’, ‘fc1obs’)
dropoutLayer(0.2,’Name’,’drop1obs’)
layerNormalizationLayer(‘Name’,’norm1obs’)
reluLayer(‘Name’,’relu1obs’)
fullyConnectedLayer(22, ‘Name’, ‘fc2obs’)
dropoutLayer(0.2,’Name’,’drop2obs’)
layerNormalizationLayer(‘Name’,’norm2obs’)
reluLayer(‘Name’,’relu2obs’)
fullyConnectedLayer(5, ‘Name’, ‘fc3obs’)
dropoutLayer(0.2,’Name’,’drop3obs’)
layerNormalizationLayer(‘Name’,’norm3obs’)
reluLayer(‘Name’,’relu3obs’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmobs’)
layerNormalizationLayer(‘Name’,’norm4obs’)
fullyConnectedLayer(1,’Name’,’fcvalue’)];
opts1 = rlRepresentationOptions("Learnrate",5e-3,"GradientThreshold",10,"UseDevice","gpu");
actor = rlStochasticActorRepresentation(actPath,obsInfo,actInfo,’Observation’,’obs’,opts1)
critic = rlValueRepresentation(obsPath,obsInfo,’Observation’,’obs’,opts1)
opts2 = rlPPOAgentOptions( "ExperienceHorizon",200,…
"SampleTIme",0.25, …
"MiniBatchSize",32, …
"EntropyLossWeight",0.5, …
"AdvantageEstimateMethod","gae", …
"GAEFactor",0.8, …
"NormalizedAdvantageMethod","current");
agent = rlPPOAgent(actor,critic,opts2) Hi, I am trying to design a reinforcement learning algorithm to perform a landing on the moon in a defined region.
The algorithm I implemented is a PPO with the environment designed in simulink. The model is designed as a continuous one. The action from RL Agent simulink block is the Thrust, the observation is the state (position and velocity). The Reward is also designed in a continuous way, with penalties outside some boundaries ("exteriorPenalty" function) and reward if inside boundaries (using exponential functions) plus some others penalties on velocities and action, properly weighted.
The model seems to work but the agent doesn’t learn as it was supposed to do. I played with PPO options to limit local minima and increase exploration to help finding optimal conditions. After lot of episodes the reward function is supposed to increase, but it varies between optimal values and the worst cases. I know that training can take lot of time due the large environment, on the other hand after a while I expect to see a better behavior. Especially if Reward values are soo high in some cases.
My questions are: how can I read in a properly way my plots of Reinforcement Learning Episode Manager? Which parameters should I change to help the agent to understand what is better? Any other comments are welcomed!
Thanks for helping!
Here my code for actor and critic generation with relative options:
actPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(50,’Name’,’fc1act’)
dropoutLayer(0.2,’Name’,’drop1act’)
layerNormalizationLayer(‘Name’,’norm1act’)
reluLayer(‘Name’,’relu1act’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmact’)
layerNormalizationLayer(‘Name’,’norm2act’)
fullyConnectedLayer(2*numAct,’Name’,’fcoutput’)
layerNormalizationLayer(‘Name’,’norm3act’)
softmaxLayer(‘Name’,’SoftactionProb’)];
obsPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(100, ‘Name’, ‘fc1obs’)
dropoutLayer(0.2,’Name’,’drop1obs’)
layerNormalizationLayer(‘Name’,’norm1obs’)
reluLayer(‘Name’,’relu1obs’)
fullyConnectedLayer(22, ‘Name’, ‘fc2obs’)
dropoutLayer(0.2,’Name’,’drop2obs’)
layerNormalizationLayer(‘Name’,’norm2obs’)
reluLayer(‘Name’,’relu2obs’)
fullyConnectedLayer(5, ‘Name’, ‘fc3obs’)
dropoutLayer(0.2,’Name’,’drop3obs’)
layerNormalizationLayer(‘Name’,’norm3obs’)
reluLayer(‘Name’,’relu3obs’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmobs’)
layerNormalizationLayer(‘Name’,’norm4obs’)
fullyConnectedLayer(1,’Name’,’fcvalue’)];
opts1 = rlRepresentationOptions("Learnrate",5e-3,"GradientThreshold",10,"UseDevice","gpu");
actor = rlStochasticActorRepresentation(actPath,obsInfo,actInfo,’Observation’,’obs’,opts1)
critic = rlValueRepresentation(obsPath,obsInfo,’Observation’,’obs’,opts1)
opts2 = rlPPOAgentOptions( "ExperienceHorizon",200,…
"SampleTIme",0.25, …
"MiniBatchSize",32, …
"EntropyLossWeight",0.5, …
"AdvantageEstimateMethod","gae", …
"GAEFactor",0.8, …
"NormalizedAdvantageMethod","current");
agent = rlPPOAgent(actor,critic,opts2) ppo, deep learning, reinforcement learning, reward MATLAB Answers — New Questions
PPO reinforcement Learning Agent doesn’t learn
Hi, I am trying to design a reinforcement learning algorithm to perform a landing on the moon in a defined region.
The algorithm I implemented is a PPO with the environment designed in simulink. The model is designed as a continuous one. The action from RL Agent simulink block is the Thrust, the observation is the state (position and velocity). The Reward is also designed in a continuous way, with penalties outside some boundaries ("exteriorPenalty" function) and reward if inside boundaries (using exponential functions) plus some others penalties on velocities and action, properly weighted.
The model seems to work but the agent doesn’t learn as it was supposed to do. I played with PPO options to limit local minima and increase exploration to help finding optimal conditions. After lot of episodes the reward function is supposed to increase, but it varies between optimal values and the worst cases. I know that training can take lot of time due the large environment, on the other hand after a while I expect to see a better behavior. Especially if Reward values are soo high in some cases.
My questions are: how can I read in a properly way my plots of Reinforcement Learning Episode Manager? Which parameters should I change to help the agent to understand what is better? Any other comments are welcomed!
Thanks for helping!
Here my code for actor and critic generation with relative options:
actPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(50,’Name’,’fc1act’)
dropoutLayer(0.2,’Name’,’drop1act’)
layerNormalizationLayer(‘Name’,’norm1act’)
reluLayer(‘Name’,’relu1act’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmact’)
layerNormalizationLayer(‘Name’,’norm2act’)
fullyConnectedLayer(2*numAct,’Name’,’fcoutput’)
layerNormalizationLayer(‘Name’,’norm3act’)
softmaxLayer(‘Name’,’SoftactionProb’)];
obsPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(100, ‘Name’, ‘fc1obs’)
dropoutLayer(0.2,’Name’,’drop1obs’)
layerNormalizationLayer(‘Name’,’norm1obs’)
reluLayer(‘Name’,’relu1obs’)
fullyConnectedLayer(22, ‘Name’, ‘fc2obs’)
dropoutLayer(0.2,’Name’,’drop2obs’)
layerNormalizationLayer(‘Name’,’norm2obs’)
reluLayer(‘Name’,’relu2obs’)
fullyConnectedLayer(5, ‘Name’, ‘fc3obs’)
dropoutLayer(0.2,’Name’,’drop3obs’)
layerNormalizationLayer(‘Name’,’norm3obs’)
reluLayer(‘Name’,’relu3obs’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmobs’)
layerNormalizationLayer(‘Name’,’norm4obs’)
fullyConnectedLayer(1,’Name’,’fcvalue’)];
opts1 = rlRepresentationOptions("Learnrate",5e-3,"GradientThreshold",10,"UseDevice","gpu");
actor = rlStochasticActorRepresentation(actPath,obsInfo,actInfo,’Observation’,’obs’,opts1)
critic = rlValueRepresentation(obsPath,obsInfo,’Observation’,’obs’,opts1)
opts2 = rlPPOAgentOptions( "ExperienceHorizon",200,…
"SampleTIme",0.25, …
"MiniBatchSize",32, …
"EntropyLossWeight",0.5, …
"AdvantageEstimateMethod","gae", …
"GAEFactor",0.8, …
"NormalizedAdvantageMethod","current");
agent = rlPPOAgent(actor,critic,opts2)Hi, I am trying to design a reinforcement learning algorithm to perform a landing on the moon in a defined region.
The algorithm I implemented is a PPO with the environment designed in simulink. The model is designed as a continuous one. The action from RL Agent simulink block is the Thrust, the observation is the state (position and velocity). The Reward is also designed in a continuous way, with penalties outside some boundaries ("exteriorPenalty" function) and reward if inside boundaries (using exponential functions) plus some others penalties on velocities and action, properly weighted.
The model seems to work but the agent doesn’t learn as it was supposed to do. I played with PPO options to limit local minima and increase exploration to help finding optimal conditions. After lot of episodes the reward function is supposed to increase, but it varies between optimal values and the worst cases. I know that training can take lot of time due the large environment, on the other hand after a while I expect to see a better behavior. Especially if Reward values are soo high in some cases.
My questions are: how can I read in a properly way my plots of Reinforcement Learning Episode Manager? Which parameters should I change to help the agent to understand what is better? Any other comments are welcomed!
Thanks for helping!
Here my code for actor and critic generation with relative options:
actPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(50,’Name’,’fc1act’)
dropoutLayer(0.2,’Name’,’drop1act’)
layerNormalizationLayer(‘Name’,’norm1act’)
reluLayer(‘Name’,’relu1act’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmact’)
layerNormalizationLayer(‘Name’,’norm2act’)
fullyConnectedLayer(2*numAct,’Name’,’fcoutput’)
layerNormalizationLayer(‘Name’,’norm3act’)
softmaxLayer(‘Name’,’SoftactionProb’)];
obsPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(100, ‘Name’, ‘fc1obs’)
dropoutLayer(0.2,’Name’,’drop1obs’)
layerNormalizationLayer(‘Name’,’norm1obs’)
reluLayer(‘Name’,’relu1obs’)
fullyConnectedLayer(22, ‘Name’, ‘fc2obs’)
dropoutLayer(0.2,’Name’,’drop2obs’)
layerNormalizationLayer(‘Name’,’norm2obs’)
reluLayer(‘Name’,’relu2obs’)
fullyConnectedLayer(5, ‘Name’, ‘fc3obs’)
dropoutLayer(0.2,’Name’,’drop3obs’)
layerNormalizationLayer(‘Name’,’norm3obs’)
reluLayer(‘Name’,’relu3obs’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmobs’)
layerNormalizationLayer(‘Name’,’norm4obs’)
fullyConnectedLayer(1,’Name’,’fcvalue’)];
opts1 = rlRepresentationOptions("Learnrate",5e-3,"GradientThreshold",10,"UseDevice","gpu");
actor = rlStochasticActorRepresentation(actPath,obsInfo,actInfo,’Observation’,’obs’,opts1)
critic = rlValueRepresentation(obsPath,obsInfo,’Observation’,’obs’,opts1)
opts2 = rlPPOAgentOptions( "ExperienceHorizon",200,…
"SampleTIme",0.25, …
"MiniBatchSize",32, …
"EntropyLossWeight",0.5, …
"AdvantageEstimateMethod","gae", …
"GAEFactor",0.8, …
"NormalizedAdvantageMethod","current");
agent = rlPPOAgent(actor,critic,opts2) Hi, I am trying to design a reinforcement learning algorithm to perform a landing on the moon in a defined region.
The algorithm I implemented is a PPO with the environment designed in simulink. The model is designed as a continuous one. The action from RL Agent simulink block is the Thrust, the observation is the state (position and velocity). The Reward is also designed in a continuous way, with penalties outside some boundaries ("exteriorPenalty" function) and reward if inside boundaries (using exponential functions) plus some others penalties on velocities and action, properly weighted.
The model seems to work but the agent doesn’t learn as it was supposed to do. I played with PPO options to limit local minima and increase exploration to help finding optimal conditions. After lot of episodes the reward function is supposed to increase, but it varies between optimal values and the worst cases. I know that training can take lot of time due the large environment, on the other hand after a while I expect to see a better behavior. Especially if Reward values are soo high in some cases.
My questions are: how can I read in a properly way my plots of Reinforcement Learning Episode Manager? Which parameters should I change to help the agent to understand what is better? Any other comments are welcomed!
Thanks for helping!
Here my code for actor and critic generation with relative options:
actPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(50,’Name’,’fc1act’)
dropoutLayer(0.2,’Name’,’drop1act’)
layerNormalizationLayer(‘Name’,’norm1act’)
reluLayer(‘Name’,’relu1act’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmact’)
layerNormalizationLayer(‘Name’,’norm2act’)
fullyConnectedLayer(2*numAct,’Name’,’fcoutput’)
layerNormalizationLayer(‘Name’,’norm3act’)
softmaxLayer(‘Name’,’SoftactionProb’)];
obsPath = [
sequenceInputLayer(numObs,’Normalization’,’none’,’Name’,’obs’)
fullyConnectedLayer(100, ‘Name’, ‘fc1obs’)
dropoutLayer(0.2,’Name’,’drop1obs’)
layerNormalizationLayer(‘Name’,’norm1obs’)
reluLayer(‘Name’,’relu1obs’)
fullyConnectedLayer(22, ‘Name’, ‘fc2obs’)
dropoutLayer(0.2,’Name’,’drop2obs’)
layerNormalizationLayer(‘Name’,’norm2obs’)
reluLayer(‘Name’,’relu2obs’)
fullyConnectedLayer(5, ‘Name’, ‘fc3obs’)
dropoutLayer(0.2,’Name’,’drop3obs’)
layerNormalizationLayer(‘Name’,’norm3obs’)
reluLayer(‘Name’,’relu3obs’)
lstmLayer(8,’OutputMode’,’sequence’,’Name’,’lstmobs’)
layerNormalizationLayer(‘Name’,’norm4obs’)
fullyConnectedLayer(1,’Name’,’fcvalue’)];
opts1 = rlRepresentationOptions("Learnrate",5e-3,"GradientThreshold",10,"UseDevice","gpu");
actor = rlStochasticActorRepresentation(actPath,obsInfo,actInfo,’Observation’,’obs’,opts1)
critic = rlValueRepresentation(obsPath,obsInfo,’Observation’,’obs’,opts1)
opts2 = rlPPOAgentOptions( "ExperienceHorizon",200,…
"SampleTIme",0.25, …
"MiniBatchSize",32, …
"EntropyLossWeight",0.5, …
"AdvantageEstimateMethod","gae", …
"GAEFactor",0.8, …
"NormalizedAdvantageMethod","current");
agent = rlPPOAgent(actor,critic,opts2) ppo, deep learning, reinforcement learning, reward MATLAB Answers — New Questions
I’m trying to sove this problem. Most of the code is given. Only the while loops must be done. I tried to do it but the calculations never ends.
% This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify% This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify % This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify sineref. while MATLAB Answers — New Questions
error in modeling pv array block
hello,
i design a pv array block and for input i use signal editor for irradiance and temperature from excel with 8760 data for one year. and i get this error. anyone can help me?hello,
i design a pv array block and for input i use signal editor for irradiance and temperature from excel with 8760 data for one year. and i get this error. anyone can help me? hello,
i design a pv array block and for input i use signal editor for irradiance and temperature from excel with 8760 data for one year. and i get this error. anyone can help me? signal editor, pv array MATLAB Answers — New Questions
I’m trying to sove this problem. Most of the code is given. Only the while loops must be done. I tried to do it but the calculations never ends.
% This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify% This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify % This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify sineref. while MATLAB Answers — New Questions
I’m trying to sove this problem. Most of the code is given. Only the while loops must be done. I tried to do it but the calculations never ends.
% This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify% This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify % This is the script for completing Task 1e only.
% The input data and modulator parameters are defined here in the same way as
% it was done for tasks 1a – 1d. This part is left unchanged.
% After the part "Initialisation and input data declaration", the specific
% code to implement Task 1e is supposed to be written.
% Step-by-step instructions will be given.
%
% As far as Matlab Grader does not support the Simulink models at the
% moment, Task 1e is supposed to be done partially in local PCs, and partially
% using the Matlab Grader tool in Moodle. Please start completing the task
% here and follow the instruction given further in the code. You will be
% explained all the details there.
%% Initialisation and input data declaratiob (just copied from tasks 1a-1d)
close all; clear all; clc
% Supply network parameters
U_grid_ll = 400; % (V) RMS line-to-line netwotk voltage
U_grid_ph = U_grid_ll/sqrt(3); % (V) RMS phase network voltage
f_grid = 50; % (Hz) network frequency
% Rectified voltage
U_DC = 3*sqrt(2)/pi*sqrt(3)*U_grid_ph; % (V) The average DC voltage of an ideal 6 pulse rectifier
%modulator parameters
m_f = 21; % frequency modulation ratio
m_a = 0.5; % amplitude modulation ratio
f_ref = 50; % (Hz) frequency of reference sine waveform
f_car = m_f * f_ref; % (Hz) carrier frequency (synchronous modulation)
%f_car = m_f * 41; % (Hz) fixed carrier frequency (asynchronous modulation)
% (Uncomment to use instead of synchronous)
T_car = 1/f_car; % (s) carrier wave period
u_tri = 1; % (V) peak triangle voltage
u_ref = m_a * u_tri; % (V) peak reference voltage
SimTime = 1; % (s) simulation length
%% Task 1e
% Step 1. Create the vector of m_a values to be simulated
% The m_a values will be used as x-axis data when building the plot
% We can use 2 options to build the plot. Both will be evaluated as
% acceptable way of task implementation.
% Option 1: Pre-defined m_a-values for a plot accurate enough and fast to run
m_a_vect = [0 0.975 1 1.025 1.05 1.075 1.1 1.13 1.15 1.2 1.3 1.5 2 2.8 4.5]; % m_a values
n_fundplot = length(m_a_vect); % number of the m_a values
% Option 2: Using evenly spaced m_a values (100 values looks good but is very slow 5-10 minutes)
% n_fundplot = 100; % number of m_a-points to run
% m_a_vect = linspace(0,4.5,n_fundplot); % evenly spaced vector with values from 0 to 4.5
% Step 2. Create the values of fundamental output voltage with sinusoidal
% reference waveform
% Note: you are free to do decide on how to switch between sinusoidal reference
% and reference which contains 3rd harmonic. Anyway, this must affect the
% Simulink model. The switching mechanism is suggested to be placed in
% "Sin-Tri PWM", and can be controlled via special variable from this
% script. For example, we can create the variable "Enable_3rd" and write the
% values of 1 or 0 into it.
%set_param(‘Enable3rd’,’sw’,’0′)
Enable_3rd = 0 ;
% But, how to implement this switching in the model, you should decide by
% yourself.
% If you did not add any circuit to add 3rd harmonic, the results of THIS
% step will be correct anyway. But, the results of the NEXT step will
% require the 3rd harmonic in reference signal anyway!
% We will use cycle "while" here. If you are good at Matlab, you can use any
% cycle. The objective of this step is to receive the correct values in
% the vector "U_fund_sine".
% Please replace ??? with the suitable lines of the code.
i_sineref = 1; % index for sinusoidal plot points
while(i_sineref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values);% length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_sine(i_sineref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_sineref = i_sineref ; % increment the "i_sineref" variable to proceed the cycle run
end
% Step 3. Create the values of fundamental output voltage when the
% reference waveform has 3rd harmonic
% This step repeats the previous step but in Simulink model the 3rd
% harmonic must be included in the reference sine signal.
% As was suggested, this can be done if we set:
Enable_3rd = 1;
% REMEMBER: the corresponding circuit/block/function in the model which
% changes its state based on this variable must be done beforehand! If you
% did not modify the model in the way to support the 3rd harmonic in PWM
% reference signal, even correct code from this step will not bring the correct
% result!
% Please replace ??? with the suitable lines of the code.
i_3rd_ext_ref = 1; % index for sinusoidal plot points
while(i_3rd_ext_ref <= (n_fundplot)) % create the condition for cycle to work.
% The cycle must run until all the values of m_a
% will be simulated!
m_a = m_a_vect(i_sineref) ; % m_a value for the point to run
u_ref = m_a*u_tri; % [V] peak reference voltage according to m_a
sim(‘ED_Ex5_T1_Sim’,SimTime); % run the model
i_u = length(U_fund.signals.values); % length of the Simulink output signal data, i.e.
% the number of thr last element in the struct "U_fund"
U_fund_3rd_ext(i_3rd_ext_ref) = U_fund.signals.values(i_u); % this line picks the last value from signal data
i_3rd_ext_ref = i_3rd_ext_ref+1; % increment the "i_3rd_ext_ref" variable to proceed the cycle run
end
save(‘m_a_vect.txt’,’m_a_vect’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_sine.txt’,’U_fund_sine’,’-ASCII’); % This is ready code, don’t modify it
save(‘U_fund_3rd_ext.txt’,’U_fund_3rd_ext’,’-ASCII’); % This is ready code, don’t modify sineref. while MATLAB Answers — New Questions