Tag Archives: matlab
Invalid use of operator
Hello,
How are you? I am using MATLAB to work on a research project. Our lab previously created a code to generate a GUI, enabling us (non-coders) to use MATLAB and carry out the research. The code was working fine, but then I tried to copy the MATLAB file from the Documents folder to a different folder. It worked fine for one case but then stopped working. I am getting this error:
X.m Line:709 Column:1 Invalid use of operator.
We have checked the code and there is no issue, especially in line 709 and its surroundings. I have tried the following steps:
Putting the MATLAB folder back in Documents -> same error.
Uninstalling MATLAB from my Mac and reinstalling the same version -> same error.
Using a previous code for the GUI that has exactly the same code in line 709 -> works fine. (I can’t use this code as the latest one has functions that I need for my work.)
Seeing that the only thing that had changed was the directory, I am assuming it has something to do with that. I must note that even after changing the directory, it worked for one sample and then stopped working. I am really stuck and would appreciate anyone’s feedback.
Thank you and kind regards,
SouvikHello,
How are you? I am using MATLAB to work on a research project. Our lab previously created a code to generate a GUI, enabling us (non-coders) to use MATLAB and carry out the research. The code was working fine, but then I tried to copy the MATLAB file from the Documents folder to a different folder. It worked fine for one case but then stopped working. I am getting this error:
X.m Line:709 Column:1 Invalid use of operator.
We have checked the code and there is no issue, especially in line 709 and its surroundings. I have tried the following steps:
Putting the MATLAB folder back in Documents -> same error.
Uninstalling MATLAB from my Mac and reinstalling the same version -> same error.
Using a previous code for the GUI that has exactly the same code in line 709 -> works fine. (I can’t use this code as the latest one has functions that I need for my work.)
Seeing that the only thing that had changed was the directory, I am assuming it has something to do with that. I must note that even after changing the directory, it worked for one sample and then stopped working. I am really stuck and would appreciate anyone’s feedback.
Thank you and kind regards,
Souvik Hello,
How are you? I am using MATLAB to work on a research project. Our lab previously created a code to generate a GUI, enabling us (non-coders) to use MATLAB and carry out the research. The code was working fine, but then I tried to copy the MATLAB file from the Documents folder to a different folder. It worked fine for one case but then stopped working. I am getting this error:
X.m Line:709 Column:1 Invalid use of operator.
We have checked the code and there is no issue, especially in line 709 and its surroundings. I have tried the following steps:
Putting the MATLAB folder back in Documents -> same error.
Uninstalling MATLAB from my Mac and reinstalling the same version -> same error.
Using a previous code for the GUI that has exactly the same code in line 709 -> works fine. (I can’t use this code as the latest one has functions that I need for my work.)
Seeing that the only thing that had changed was the directory, I am assuming it has something to do with that. I must note that even after changing the directory, it worked for one sample and then stopped working. I am really stuck and would appreciate anyone’s feedback.
Thank you and kind regards,
Souvik invalid use of operator MATLAB Answers — New Questions
How do I generate constant harmonic currents
I can use the three phase constant current block to generate a constant current of the fundamental frequency. How do I generate constant three phase harmonic currents? For example, 5A of the 7th harmonic. I don’t see a frequency setting in the block parameters for the three phase constant current block.
Thanks,
DavidI can use the three phase constant current block to generate a constant current of the fundamental frequency. How do I generate constant three phase harmonic currents? For example, 5A of the 7th harmonic. I don’t see a frequency setting in the block parameters for the three phase constant current block.
Thanks,
David I can use the three phase constant current block to generate a constant current of the fundamental frequency. How do I generate constant three phase harmonic currents? For example, 5A of the 7th harmonic. I don’t see a frequency setting in the block parameters for the three phase constant current block.
Thanks,
David constant current MATLAB Answers — New Questions
How to solve coupled differential equations using ode45 for “n” modes
Hello everyone,
I am trying to solve some differential equation in matlab using ode45. The equations are as shown below:
I have written the equations in state space form where ydot_1(i) is , ydot_2(i) is , ydot_3(i) is and ydot_4(i) is . In the equation of motion of x, eq(2), x terms are not in terms of “ i “ but I have written them like that (so ydot_3(i) is and ydot_4(i) is )b ecause of the loop that I use on the function below. So the “for” loop, for each time step, lets say starting at solves first the ydot terms for each mode for i = 1:n and then gets out of the loop, goes to the new time step and then solve again for each mode. However, since for each time step it will start from the first mode again, and ydot_1(i) and ydot_2(i) depend on ydot_3(i) and ydot_4(i) , then I am solving the equation of x, eq.2, for each mode. For the new time step, before starting with the first mode again I am defining the
ydot_1=y(1:n); %displacement beam
ydot_2=y(n+1:2*n); %velocity beam
ydot_3=y(2*n+1:3*n); %displacement mass
ydot_4=y(3*n+1:4*n); %velocity mass
v_m=0;
x_m=0;
x_c_prev = x_c_prev_modes{1};
so it can start with the data from the previous first mode (first mode of the previous time step). My problem is that when I solve for 1 mode only, so for n=1 and get the solution du_1= y(:,n+i).*sin(i*pi.* x_c_values_new); and then solve for n=2 but still get the solution du_1= y(:,n+i).*sin(i*pi.* x_c_values_new); for the first mode only, these first modes do not match. The solution have the same shape but differ in amplitude. The same happens with I use n=20, for example, but again plot only the first mode du_1. The solution changes from the first mode obtained when n=2 and from the first mode obtained for n=1. I have checked for days and cant see my mistake so have reached desperation. Would really appreciate your help! thank youuu!
clear all
clc
global xi xi_b r_w r_m mu_s mu_k v alpha P l a w l_0 n x_c_prev x_c_prev_modes
dt=0.01;
tspan = (0:dt:150).’;
% parameters
xi=0.14;
xi_b=0.0025;
r_w=4.5;
r_m=4.8;
mu_s=0.5;
mu_k=0.2 ;
alpha=300;
P=0.002;
l=1/75;
l_0=0.25;
a=0;
w=9;
v=0.005;
% Initialize y_c_prev and the array to store x_c values
x_c_prev = 0;
global t_values x_c_values; % Declare t_values and x_c_values as global
t_values = tspan; % Store time values
x_c_values = zeros(size(tspan)); % Initialize array to store x_c values
n=1;
y0 = zeros(4*n,1);
y0(3*n+1) = -v;
% Initialize y_c_prev
x_c_prev = 0;
% Define your initial value for x_c_prev
x_c_prev_initial = 0;
% Initialize x_c_prev_modes, assuming you have ‘n’ modes
x_c_prev_modes = cell(1, n);
% Initialize the first mode’s x_c_prev
x_c_prev_modes{1} = x_c_prev_initial;
[t,y] = ode45(‘rhs_cont4’,tspan,y0);
for i=1:1
u_1= y(:,i).*sin(i*pi.* x_c_values_new);
du_1= y(:,n+i).*sin(i*pi.* x_c_values_new);
end
figure
plot(t,du_1)
legend("beam vel mode 1")
function ydot=rhs_cont4(t,y)
global xi xi_b r_w r_m mu_s mu_k v alpha P a w l_0 n x_c_prev x_c_prev_modes
% ydot_1=y(1:n); %displacement beam
% ydot_2=y(n+1:2*n); %velocity beam
% ydot_3=y(2*n+1:3*n); %displacement mass
% ydot_4=y(3*n+1:4*n); %velocity mass
ydot_1=zeros(n,1); %displacement beam
ydot_2=zeros(n,1); %velocity beam
ydot_3=zeros(n,1); %displacement mass
ydot_4=zeros(n,1); %velocity mass%
v_m=0;
x_m=0;
x_c_prev = x_c_prev_modes{1};
% fprintf(‘x_c_prev %.7fn ‘, x_c_prev);
for i = 1:n
x_m=y(i)*sin(i*pi*x_c_prev)+x_m;
x_c=y(2*n+i)+v*t+l_0-x_m;
x_c_prev = x_c; % Update y_c_prev for the next iteration
x_c_prev_modes{i} = x_c_prev;
%Store y_c values at the corresponding time step
global t_values x_c_values; % Access global variables
[~, idx] = min(abs(t – t_values)); % Find the index of the closest time step
x_c_values(idx) = x_c; % Store y_c at the corresponding time step
v_m=y(n+i)*sin(i*pi*x_c)+v_m;
ydot_1(i) = y(n+i);
ydot_2(i) = -2*xi_b*r_w*y(n+i)-(r_w*i)^2*y(i)+2*sign(y(3*n+i)+v-v_m)*(mu_k+(mu_s-mu_k)*exp(-alpha*abs(y(3*n+i)+v-v_m)))*P*sin(i*pi*x_c);
ydot_3(i) =y(3*n+i);
ydot_4(i) =-2*xi*y(3*n+i)-y(2*n+i)-r_m*sign(y(3*n+i)+v-v_m)*(mu_k+(mu_s-mu_k)*exp(-alpha*abs(y(3*n+i)+v-v_m)))*P+a*w^2*sin(w*t);
%
% if i == 1
% fprintf(‘Time: %.4f, ydot_1: %.7fn, ydot_2: %.7fn, ydot_3: %.7fn, ydot_4: %.7fn ‘, t, ydot_1(i), ydot_2(i), ydot_3(i), ydot_4(i));
% end
end
ydot = [ydot_1; ydot_2; ydot_3; ydot_4];
endHello everyone,
I am trying to solve some differential equation in matlab using ode45. The equations are as shown below:
I have written the equations in state space form where ydot_1(i) is , ydot_2(i) is , ydot_3(i) is and ydot_4(i) is . In the equation of motion of x, eq(2), x terms are not in terms of “ i “ but I have written them like that (so ydot_3(i) is and ydot_4(i) is )b ecause of the loop that I use on the function below. So the “for” loop, for each time step, lets say starting at solves first the ydot terms for each mode for i = 1:n and then gets out of the loop, goes to the new time step and then solve again for each mode. However, since for each time step it will start from the first mode again, and ydot_1(i) and ydot_2(i) depend on ydot_3(i) and ydot_4(i) , then I am solving the equation of x, eq.2, for each mode. For the new time step, before starting with the first mode again I am defining the
ydot_1=y(1:n); %displacement beam
ydot_2=y(n+1:2*n); %velocity beam
ydot_3=y(2*n+1:3*n); %displacement mass
ydot_4=y(3*n+1:4*n); %velocity mass
v_m=0;
x_m=0;
x_c_prev = x_c_prev_modes{1};
so it can start with the data from the previous first mode (first mode of the previous time step). My problem is that when I solve for 1 mode only, so for n=1 and get the solution du_1= y(:,n+i).*sin(i*pi.* x_c_values_new); and then solve for n=2 but still get the solution du_1= y(:,n+i).*sin(i*pi.* x_c_values_new); for the first mode only, these first modes do not match. The solution have the same shape but differ in amplitude. The same happens with I use n=20, for example, but again plot only the first mode du_1. The solution changes from the first mode obtained when n=2 and from the first mode obtained for n=1. I have checked for days and cant see my mistake so have reached desperation. Would really appreciate your help! thank youuu!
clear all
clc
global xi xi_b r_w r_m mu_s mu_k v alpha P l a w l_0 n x_c_prev x_c_prev_modes
dt=0.01;
tspan = (0:dt:150).’;
% parameters
xi=0.14;
xi_b=0.0025;
r_w=4.5;
r_m=4.8;
mu_s=0.5;
mu_k=0.2 ;
alpha=300;
P=0.002;
l=1/75;
l_0=0.25;
a=0;
w=9;
v=0.005;
% Initialize y_c_prev and the array to store x_c values
x_c_prev = 0;
global t_values x_c_values; % Declare t_values and x_c_values as global
t_values = tspan; % Store time values
x_c_values = zeros(size(tspan)); % Initialize array to store x_c values
n=1;
y0 = zeros(4*n,1);
y0(3*n+1) = -v;
% Initialize y_c_prev
x_c_prev = 0;
% Define your initial value for x_c_prev
x_c_prev_initial = 0;
% Initialize x_c_prev_modes, assuming you have ‘n’ modes
x_c_prev_modes = cell(1, n);
% Initialize the first mode’s x_c_prev
x_c_prev_modes{1} = x_c_prev_initial;
[t,y] = ode45(‘rhs_cont4’,tspan,y0);
for i=1:1
u_1= y(:,i).*sin(i*pi.* x_c_values_new);
du_1= y(:,n+i).*sin(i*pi.* x_c_values_new);
end
figure
plot(t,du_1)
legend("beam vel mode 1")
function ydot=rhs_cont4(t,y)
global xi xi_b r_w r_m mu_s mu_k v alpha P a w l_0 n x_c_prev x_c_prev_modes
% ydot_1=y(1:n); %displacement beam
% ydot_2=y(n+1:2*n); %velocity beam
% ydot_3=y(2*n+1:3*n); %displacement mass
% ydot_4=y(3*n+1:4*n); %velocity mass
ydot_1=zeros(n,1); %displacement beam
ydot_2=zeros(n,1); %velocity beam
ydot_3=zeros(n,1); %displacement mass
ydot_4=zeros(n,1); %velocity mass%
v_m=0;
x_m=0;
x_c_prev = x_c_prev_modes{1};
% fprintf(‘x_c_prev %.7fn ‘, x_c_prev);
for i = 1:n
x_m=y(i)*sin(i*pi*x_c_prev)+x_m;
x_c=y(2*n+i)+v*t+l_0-x_m;
x_c_prev = x_c; % Update y_c_prev for the next iteration
x_c_prev_modes{i} = x_c_prev;
%Store y_c values at the corresponding time step
global t_values x_c_values; % Access global variables
[~, idx] = min(abs(t – t_values)); % Find the index of the closest time step
x_c_values(idx) = x_c; % Store y_c at the corresponding time step
v_m=y(n+i)*sin(i*pi*x_c)+v_m;
ydot_1(i) = y(n+i);
ydot_2(i) = -2*xi_b*r_w*y(n+i)-(r_w*i)^2*y(i)+2*sign(y(3*n+i)+v-v_m)*(mu_k+(mu_s-mu_k)*exp(-alpha*abs(y(3*n+i)+v-v_m)))*P*sin(i*pi*x_c);
ydot_3(i) =y(3*n+i);
ydot_4(i) =-2*xi*y(3*n+i)-y(2*n+i)-r_m*sign(y(3*n+i)+v-v_m)*(mu_k+(mu_s-mu_k)*exp(-alpha*abs(y(3*n+i)+v-v_m)))*P+a*w^2*sin(w*t);
%
% if i == 1
% fprintf(‘Time: %.4f, ydot_1: %.7fn, ydot_2: %.7fn, ydot_3: %.7fn, ydot_4: %.7fn ‘, t, ydot_1(i), ydot_2(i), ydot_3(i), ydot_4(i));
% end
end
ydot = [ydot_1; ydot_2; ydot_3; ydot_4];
end Hello everyone,
I am trying to solve some differential equation in matlab using ode45. The equations are as shown below:
I have written the equations in state space form where ydot_1(i) is , ydot_2(i) is , ydot_3(i) is and ydot_4(i) is . In the equation of motion of x, eq(2), x terms are not in terms of “ i “ but I have written them like that (so ydot_3(i) is and ydot_4(i) is )b ecause of the loop that I use on the function below. So the “for” loop, for each time step, lets say starting at solves first the ydot terms for each mode for i = 1:n and then gets out of the loop, goes to the new time step and then solve again for each mode. However, since for each time step it will start from the first mode again, and ydot_1(i) and ydot_2(i) depend on ydot_3(i) and ydot_4(i) , then I am solving the equation of x, eq.2, for each mode. For the new time step, before starting with the first mode again I am defining the
ydot_1=y(1:n); %displacement beam
ydot_2=y(n+1:2*n); %velocity beam
ydot_3=y(2*n+1:3*n); %displacement mass
ydot_4=y(3*n+1:4*n); %velocity mass
v_m=0;
x_m=0;
x_c_prev = x_c_prev_modes{1};
so it can start with the data from the previous first mode (first mode of the previous time step). My problem is that when I solve for 1 mode only, so for n=1 and get the solution du_1= y(:,n+i).*sin(i*pi.* x_c_values_new); and then solve for n=2 but still get the solution du_1= y(:,n+i).*sin(i*pi.* x_c_values_new); for the first mode only, these first modes do not match. The solution have the same shape but differ in amplitude. The same happens with I use n=20, for example, but again plot only the first mode du_1. The solution changes from the first mode obtained when n=2 and from the first mode obtained for n=1. I have checked for days and cant see my mistake so have reached desperation. Would really appreciate your help! thank youuu!
clear all
clc
global xi xi_b r_w r_m mu_s mu_k v alpha P l a w l_0 n x_c_prev x_c_prev_modes
dt=0.01;
tspan = (0:dt:150).’;
% parameters
xi=0.14;
xi_b=0.0025;
r_w=4.5;
r_m=4.8;
mu_s=0.5;
mu_k=0.2 ;
alpha=300;
P=0.002;
l=1/75;
l_0=0.25;
a=0;
w=9;
v=0.005;
% Initialize y_c_prev and the array to store x_c values
x_c_prev = 0;
global t_values x_c_values; % Declare t_values and x_c_values as global
t_values = tspan; % Store time values
x_c_values = zeros(size(tspan)); % Initialize array to store x_c values
n=1;
y0 = zeros(4*n,1);
y0(3*n+1) = -v;
% Initialize y_c_prev
x_c_prev = 0;
% Define your initial value for x_c_prev
x_c_prev_initial = 0;
% Initialize x_c_prev_modes, assuming you have ‘n’ modes
x_c_prev_modes = cell(1, n);
% Initialize the first mode’s x_c_prev
x_c_prev_modes{1} = x_c_prev_initial;
[t,y] = ode45(‘rhs_cont4’,tspan,y0);
for i=1:1
u_1= y(:,i).*sin(i*pi.* x_c_values_new);
du_1= y(:,n+i).*sin(i*pi.* x_c_values_new);
end
figure
plot(t,du_1)
legend("beam vel mode 1")
function ydot=rhs_cont4(t,y)
global xi xi_b r_w r_m mu_s mu_k v alpha P a w l_0 n x_c_prev x_c_prev_modes
% ydot_1=y(1:n); %displacement beam
% ydot_2=y(n+1:2*n); %velocity beam
% ydot_3=y(2*n+1:3*n); %displacement mass
% ydot_4=y(3*n+1:4*n); %velocity mass
ydot_1=zeros(n,1); %displacement beam
ydot_2=zeros(n,1); %velocity beam
ydot_3=zeros(n,1); %displacement mass
ydot_4=zeros(n,1); %velocity mass%
v_m=0;
x_m=0;
x_c_prev = x_c_prev_modes{1};
% fprintf(‘x_c_prev %.7fn ‘, x_c_prev);
for i = 1:n
x_m=y(i)*sin(i*pi*x_c_prev)+x_m;
x_c=y(2*n+i)+v*t+l_0-x_m;
x_c_prev = x_c; % Update y_c_prev for the next iteration
x_c_prev_modes{i} = x_c_prev;
%Store y_c values at the corresponding time step
global t_values x_c_values; % Access global variables
[~, idx] = min(abs(t – t_values)); % Find the index of the closest time step
x_c_values(idx) = x_c; % Store y_c at the corresponding time step
v_m=y(n+i)*sin(i*pi*x_c)+v_m;
ydot_1(i) = y(n+i);
ydot_2(i) = -2*xi_b*r_w*y(n+i)-(r_w*i)^2*y(i)+2*sign(y(3*n+i)+v-v_m)*(mu_k+(mu_s-mu_k)*exp(-alpha*abs(y(3*n+i)+v-v_m)))*P*sin(i*pi*x_c);
ydot_3(i) =y(3*n+i);
ydot_4(i) =-2*xi*y(3*n+i)-y(2*n+i)-r_m*sign(y(3*n+i)+v-v_m)*(mu_k+(mu_s-mu_k)*exp(-alpha*abs(y(3*n+i)+v-v_m)))*P+a*w^2*sin(w*t);
%
% if i == 1
% fprintf(‘Time: %.4f, ydot_1: %.7fn, ydot_2: %.7fn, ydot_3: %.7fn, ydot_4: %.7fn ‘, t, ydot_1(i), ydot_2(i), ydot_3(i), ydot_4(i));
% end
end
ydot = [ydot_1; ydot_2; ydot_3; ydot_4];
end ode45, differential equations MATLAB Answers — New Questions
How can i make optimization of nonlinear spring
How can i make optimization of nonlinear spring ?How can i make optimization of nonlinear spring ? How can i make optimization of nonlinear spring ? optimization, synthesis MATLAB Answers — New Questions
How can I use selections from multiple uidropdowns as function inputs?
I’m using two (2) uidropdowns with a valuechangedfcn to live update the x-y axes for a plot based on the selected variable. I can’t figure out how to simultaneously pass the information from both dropdowns to my plotting function. For example, say I have data for three variables: time, position, and velocity, and I have two drop downs each containing the same three variables for the x and y axes. I’m unable to retain a previous variable selection for the x-axis once I select a new variable for the y-axis, so it just reverts to the initialized x-variable. Is there a way to store the selection from each dropdown simultaneouslyI’m using two (2) uidropdowns with a valuechangedfcn to live update the x-y axes for a plot based on the selected variable. I can’t figure out how to simultaneously pass the information from both dropdowns to my plotting function. For example, say I have data for three variables: time, position, and velocity, and I have two drop downs each containing the same three variables for the x and y axes. I’m unable to retain a previous variable selection for the x-axis once I select a new variable for the y-axis, so it just reverts to the initialized x-variable. Is there a way to store the selection from each dropdown simultaneously I’m using two (2) uidropdowns with a valuechangedfcn to live update the x-y axes for a plot based on the selected variable. I can’t figure out how to simultaneously pass the information from both dropdowns to my plotting function. For example, say I have data for three variables: time, position, and velocity, and I have two drop downs each containing the same three variables for the x and y axes. I’m unable to retain a previous variable selection for the x-axis once I select a new variable for the y-axis, so it just reverts to the initialized x-variable. Is there a way to store the selection from each dropdown simultaneously uidropdrown, appdesigner, plot, gui MATLAB Answers — New Questions
How do I build standalone applications and create associated installers in the command line outside of MATLAB without using “deploytool” in MATLAB R2023b on Windows?
I am using MATLAB R2023b on a Windows machine and wish to build standalone applications and created the associated installers in the command line outside of MATLAB as part of a build environment.
I currently do this by invoking "deploytool" via the command line. However, I see that the "-package" option for "deploytool" will be removed in the future. Are there any alternatives for "deploytool" to complete this workflow on the command line?
Ideally, this alternate command line approach would reuse the PRJ files generated by "deploytool". I have looked into using "mcc", but it doesn’t generate the associated installer.I am using MATLAB R2023b on a Windows machine and wish to build standalone applications and created the associated installers in the command line outside of MATLAB as part of a build environment.
I currently do this by invoking "deploytool" via the command line. However, I see that the "-package" option for "deploytool" will be removed in the future. Are there any alternatives for "deploytool" to complete this workflow on the command line?
Ideally, this alternate command line approach would reuse the PRJ files generated by "deploytool". I have looked into using "mcc", but it doesn’t generate the associated installer. I am using MATLAB R2023b on a Windows machine and wish to build standalone applications and created the associated installers in the command line outside of MATLAB as part of a build environment.
I currently do this by invoking "deploytool" via the command line. However, I see that the "-package" option for "deploytool" will be removed in the future. Are there any alternatives for "deploytool" to complete this workflow on the command line?
Ideally, this alternate command line approach would reuse the PRJ files generated by "deploytool". I have looked into using "mcc", but it doesn’t generate the associated installer. deploytool, mcc, deployment, standaloneapplication, matlabcompiler MATLAB Answers — New Questions
imregcorr() misaligns images badly
[tform, peakregcorr] = imregcorr(SourceImageAdj,SourceRef, …
TargetImageAdj,TargetRef, …
‘transformType’, ‘similarity’, …
‘Window’, true);
RegisteredImage = imwarp(SourceImageAdj,SourceRef, tform, ‘linear’, …
‘OutputView’, TargetRef);
disp(peakregcorr)
figure, imshowpair(TargetImageAdj,TargetRef,RegisteredImage, TargetRef)
above is my code to correlate 2 images of different sizes. the goal is to find the correlation between the images to determine what pixel location a point of interest might lie in both images. However, imregcorr consistently misses the mark badly.
Whereas the code above might output a tform object – Dimensionality: 2, Scale: 0.4254, RotationAngle: 2.4851, Translation: [-0.3269 -0.0904]
A more correct tform object (based upon the output image would look like – Dimensionality: 2, Scale: 1, RotationAngle: -1, Translation: [0.0640 0]
The SourceRef and TargetRef seem correct, so Im not sure what is causing the issue[tform, peakregcorr] = imregcorr(SourceImageAdj,SourceRef, …
TargetImageAdj,TargetRef, …
‘transformType’, ‘similarity’, …
‘Window’, true);
RegisteredImage = imwarp(SourceImageAdj,SourceRef, tform, ‘linear’, …
‘OutputView’, TargetRef);
disp(peakregcorr)
figure, imshowpair(TargetImageAdj,TargetRef,RegisteredImage, TargetRef)
above is my code to correlate 2 images of different sizes. the goal is to find the correlation between the images to determine what pixel location a point of interest might lie in both images. However, imregcorr consistently misses the mark badly.
Whereas the code above might output a tform object – Dimensionality: 2, Scale: 0.4254, RotationAngle: 2.4851, Translation: [-0.3269 -0.0904]
A more correct tform object (based upon the output image would look like – Dimensionality: 2, Scale: 1, RotationAngle: -1, Translation: [0.0640 0]
The SourceRef and TargetRef seem correct, so Im not sure what is causing the issue [tform, peakregcorr] = imregcorr(SourceImageAdj,SourceRef, …
TargetImageAdj,TargetRef, …
‘transformType’, ‘similarity’, …
‘Window’, true);
RegisteredImage = imwarp(SourceImageAdj,SourceRef, tform, ‘linear’, …
‘OutputView’, TargetRef);
disp(peakregcorr)
figure, imshowpair(TargetImageAdj,TargetRef,RegisteredImage, TargetRef)
above is my code to correlate 2 images of different sizes. the goal is to find the correlation between the images to determine what pixel location a point of interest might lie in both images. However, imregcorr consistently misses the mark badly.
Whereas the code above might output a tform object – Dimensionality: 2, Scale: 0.4254, RotationAngle: 2.4851, Translation: [-0.3269 -0.0904]
A more correct tform object (based upon the output image would look like – Dimensionality: 2, Scale: 1, RotationAngle: -1, Translation: [0.0640 0]
The SourceRef and TargetRef seem correct, so Im not sure what is causing the issue image processing MATLAB Answers — New Questions
How do I install MATLAB Web App Server on cloud?
I would like to install MATLAB Web App Server on a cloud platform like Azure or AWS, so that my team can access the web apps from anywhere.
Is there any documentation for installing Web App Server on the cloud?I would like to install MATLAB Web App Server on a cloud platform like Azure or AWS, so that my team can access the web apps from anywhere.
Is there any documentation for installing Web App Server on the cloud? I would like to install MATLAB Web App Server on a cloud platform like Azure or AWS, so that my team can access the web apps from anywhere.
Is there any documentation for installing Web App Server on the cloud? MATLAB Answers — New Questions
Time-dependent dynamic problem with nonlinear stiffness using ode45
I am solving a time-dependent finite element problem with nonlinearities in the stiffness matrix which takes the following form:
where the dot symbolizes derivative with respect to time, U is the displacement vector, M is the mass matrix, C is the damping matrix, K(U) is the stiffness matrix which depends on U, and F is an external force. I would like to use ode45 to solve the dynamic problem. The general flow for solving this problem would be the following:
Calculate the stiffness matrix K using the latest displacement U (Initial condition if it is the first time step).
Formulate the state-space equations using K matrix, M matrix, C matrix, and F vector.
Integrate the state-space equations with ode45 to caclulate the new displacement U.
Recalculate the K matrix with the new displacement U. Check if the residual error meets the preselected tolerance.
If the error is met, update velocities and accelerations, and go to the next time step. If the error is not met, then go back to step 1 using this latest K matrix.
I am familiar with solving this problem without the nonlinearity in K. However, I am unsure how to update the K matrix at every time step within the ode45 framework.
Thank you for the guidance!I am solving a time-dependent finite element problem with nonlinearities in the stiffness matrix which takes the following form:
where the dot symbolizes derivative with respect to time, U is the displacement vector, M is the mass matrix, C is the damping matrix, K(U) is the stiffness matrix which depends on U, and F is an external force. I would like to use ode45 to solve the dynamic problem. The general flow for solving this problem would be the following:
Calculate the stiffness matrix K using the latest displacement U (Initial condition if it is the first time step).
Formulate the state-space equations using K matrix, M matrix, C matrix, and F vector.
Integrate the state-space equations with ode45 to caclulate the new displacement U.
Recalculate the K matrix with the new displacement U. Check if the residual error meets the preselected tolerance.
If the error is met, update velocities and accelerations, and go to the next time step. If the error is not met, then go back to step 1 using this latest K matrix.
I am familiar with solving this problem without the nonlinearity in K. However, I am unsure how to update the K matrix at every time step within the ode45 framework.
Thank you for the guidance! I am solving a time-dependent finite element problem with nonlinearities in the stiffness matrix which takes the following form:
where the dot symbolizes derivative with respect to time, U is the displacement vector, M is the mass matrix, C is the damping matrix, K(U) is the stiffness matrix which depends on U, and F is an external force. I would like to use ode45 to solve the dynamic problem. The general flow for solving this problem would be the following:
Calculate the stiffness matrix K using the latest displacement U (Initial condition if it is the first time step).
Formulate the state-space equations using K matrix, M matrix, C matrix, and F vector.
Integrate the state-space equations with ode45 to caclulate the new displacement U.
Recalculate the K matrix with the new displacement U. Check if the residual error meets the preselected tolerance.
If the error is met, update velocities and accelerations, and go to the next time step. If the error is not met, then go back to step 1 using this latest K matrix.
I am familiar with solving this problem without the nonlinearity in K. However, I am unsure how to update the K matrix at every time step within the ode45 framework.
Thank you for the guidance! nonlinear-dynamics, ode45 MATLAB Answers — New Questions
Trying to understand the implementation of boundary conditions in this MATLAB code
I am following with the textbook: Lloyd N. Trefethen, Spectral Methods in MATLAB, SIAM and trying to understand a very particular MATLAB code. This problem is shown in program 37 and it considers 2nd order wave equation in 2D with periodic boundary conditions in x and Neumann boundary conditions in y:
and the boundary conditions:
So the code is:
%x variable in [-A,A], Fourier
A=3; Nx=50; dx =2*A/Nx; x= -A+dx*(1:Nx)’;
D2x = (pi/A)^2*toeplitz([-1/(3*(dx/A)^2)-1/6 …
0.5*(-1).^(2:Nx)./sin((pi*dx/A)*(1:Nx-1)/2).^2]);
%y variable in [-1,1], chebyshev:
Ny=15;
[Dy,y] = cheb(Ny);
D2y=Dy^2;
BC=-Dy([1 Ny+1],[1 Ny+1])Dy([1 Ny+1],2:Ny); %Homogenous Neumann BCs for |y|=1
%Grid and initial data:
[xx,yy] = meshgrid(x,y);
vv=exp(-8*((xx+1.5).^2 + yy.^2));
dt = 5/(Nx+Ny^2);
vvold = exp(-8*((xx+dt+1.5).^2+yy.^2));
%Time stepping by leap frog forula:
dt = 5/(Nx+Ny^2);clf; plotgap=round(2/dt); dt=2/plotgap;
for n=0:2*plotgap
t=n*dt;
if rem(n+.5,plotgap)<1
subplot(3,1,n/plotgap+1), mesh(xx,yy,vv), view(-10,60)
colormap([0 0 0])
text(-2.5,1,.5,[‘t=’ num2str(t)],’fontsize’,18),,grid off, drawnow
end
vvnew= 2*vv – vvold + dt^2*(vv*D2x+D2y*vv);
vvold = vv; vv = vvnew;
vv([1 Ny+1],:) = BC*vv(2:Ny,:); %Neumann BCs for |y|=1
%first row and last row in vv = BC x
%From Program 33
end
Now, I have a similar problem where I am trying to reproduce the exact BCs for a 2D Poisson’s equation/problem. What I am struggling to understand is this line:
BC=-Dy([1 Ny+1],[1 Ny+1])Dy([1 Ny+1],2:Ny); %Homogenous Neumann BCs for |y|=1
I am not sure what is the author doing here so I can reproduce these exact BCs in my code. My understanding is we want to replace the first/last rows of D2 with values of first/last rows of D and set them to zero? Meaning we want to set the values if the first derivative to zero? Is this correct or am I misunderstanding the syntax. Thanks.
The Cheb function:
function [ D, x ] = cheb ( N )
if ( N == 0 )
D = 0.0;
x = 1.0;
return
end
x = cos ( pi * ( 0 : N ) / N )’;
c = [ 2.0; ones(N-1,1); 2.0 ] .* (-1.0).^(0:N)’;
X = repmat ( x, 1, N + 1 );
dX = X – X’;
% Set the off diagonal entries.
D =( c * (1.0 ./ c )’ ) ./ ( dX + ( eye ( N + 1 ) ) );
% Diagonal entries.
D = D – diag ( sum ( D’ ) );
return
endI am following with the textbook: Lloyd N. Trefethen, Spectral Methods in MATLAB, SIAM and trying to understand a very particular MATLAB code. This problem is shown in program 37 and it considers 2nd order wave equation in 2D with periodic boundary conditions in x and Neumann boundary conditions in y:
and the boundary conditions:
So the code is:
%x variable in [-A,A], Fourier
A=3; Nx=50; dx =2*A/Nx; x= -A+dx*(1:Nx)’;
D2x = (pi/A)^2*toeplitz([-1/(3*(dx/A)^2)-1/6 …
0.5*(-1).^(2:Nx)./sin((pi*dx/A)*(1:Nx-1)/2).^2]);
%y variable in [-1,1], chebyshev:
Ny=15;
[Dy,y] = cheb(Ny);
D2y=Dy^2;
BC=-Dy([1 Ny+1],[1 Ny+1])Dy([1 Ny+1],2:Ny); %Homogenous Neumann BCs for |y|=1
%Grid and initial data:
[xx,yy] = meshgrid(x,y);
vv=exp(-8*((xx+1.5).^2 + yy.^2));
dt = 5/(Nx+Ny^2);
vvold = exp(-8*((xx+dt+1.5).^2+yy.^2));
%Time stepping by leap frog forula:
dt = 5/(Nx+Ny^2);clf; plotgap=round(2/dt); dt=2/plotgap;
for n=0:2*plotgap
t=n*dt;
if rem(n+.5,plotgap)<1
subplot(3,1,n/plotgap+1), mesh(xx,yy,vv), view(-10,60)
colormap([0 0 0])
text(-2.5,1,.5,[‘t=’ num2str(t)],’fontsize’,18),,grid off, drawnow
end
vvnew= 2*vv – vvold + dt^2*(vv*D2x+D2y*vv);
vvold = vv; vv = vvnew;
vv([1 Ny+1],:) = BC*vv(2:Ny,:); %Neumann BCs for |y|=1
%first row and last row in vv = BC x
%From Program 33
end
Now, I have a similar problem where I am trying to reproduce the exact BCs for a 2D Poisson’s equation/problem. What I am struggling to understand is this line:
BC=-Dy([1 Ny+1],[1 Ny+1])Dy([1 Ny+1],2:Ny); %Homogenous Neumann BCs for |y|=1
I am not sure what is the author doing here so I can reproduce these exact BCs in my code. My understanding is we want to replace the first/last rows of D2 with values of first/last rows of D and set them to zero? Meaning we want to set the values if the first derivative to zero? Is this correct or am I misunderstanding the syntax. Thanks.
The Cheb function:
function [ D, x ] = cheb ( N )
if ( N == 0 )
D = 0.0;
x = 1.0;
return
end
x = cos ( pi * ( 0 : N ) / N )’;
c = [ 2.0; ones(N-1,1); 2.0 ] .* (-1.0).^(0:N)’;
X = repmat ( x, 1, N + 1 );
dX = X – X’;
% Set the off diagonal entries.
D =( c * (1.0 ./ c )’ ) ./ ( dX + ( eye ( N + 1 ) ) );
% Diagonal entries.
D = D – diag ( sum ( D’ ) );
return
end I am following with the textbook: Lloyd N. Trefethen, Spectral Methods in MATLAB, SIAM and trying to understand a very particular MATLAB code. This problem is shown in program 37 and it considers 2nd order wave equation in 2D with periodic boundary conditions in x and Neumann boundary conditions in y:
and the boundary conditions:
So the code is:
%x variable in [-A,A], Fourier
A=3; Nx=50; dx =2*A/Nx; x= -A+dx*(1:Nx)’;
D2x = (pi/A)^2*toeplitz([-1/(3*(dx/A)^2)-1/6 …
0.5*(-1).^(2:Nx)./sin((pi*dx/A)*(1:Nx-1)/2).^2]);
%y variable in [-1,1], chebyshev:
Ny=15;
[Dy,y] = cheb(Ny);
D2y=Dy^2;
BC=-Dy([1 Ny+1],[1 Ny+1])Dy([1 Ny+1],2:Ny); %Homogenous Neumann BCs for |y|=1
%Grid and initial data:
[xx,yy] = meshgrid(x,y);
vv=exp(-8*((xx+1.5).^2 + yy.^2));
dt = 5/(Nx+Ny^2);
vvold = exp(-8*((xx+dt+1.5).^2+yy.^2));
%Time stepping by leap frog forula:
dt = 5/(Nx+Ny^2);clf; plotgap=round(2/dt); dt=2/plotgap;
for n=0:2*plotgap
t=n*dt;
if rem(n+.5,plotgap)<1
subplot(3,1,n/plotgap+1), mesh(xx,yy,vv), view(-10,60)
colormap([0 0 0])
text(-2.5,1,.5,[‘t=’ num2str(t)],’fontsize’,18),,grid off, drawnow
end
vvnew= 2*vv – vvold + dt^2*(vv*D2x+D2y*vv);
vvold = vv; vv = vvnew;
vv([1 Ny+1],:) = BC*vv(2:Ny,:); %Neumann BCs for |y|=1
%first row and last row in vv = BC x
%From Program 33
end
Now, I have a similar problem where I am trying to reproduce the exact BCs for a 2D Poisson’s equation/problem. What I am struggling to understand is this line:
BC=-Dy([1 Ny+1],[1 Ny+1])Dy([1 Ny+1],2:Ny); %Homogenous Neumann BCs for |y|=1
I am not sure what is the author doing here so I can reproduce these exact BCs in my code. My understanding is we want to replace the first/last rows of D2 with values of first/last rows of D and set them to zero? Meaning we want to set the values if the first derivative to zero? Is this correct or am I misunderstanding the syntax. Thanks.
The Cheb function:
function [ D, x ] = cheb ( N )
if ( N == 0 )
D = 0.0;
x = 1.0;
return
end
x = cos ( pi * ( 0 : N ) / N )’;
c = [ 2.0; ones(N-1,1); 2.0 ] .* (-1.0).^(0:N)’;
X = repmat ( x, 1, N + 1 );
dX = X – X’;
% Set the off diagonal entries.
D =( c * (1.0 ./ c )’ ) ./ ( dX + ( eye ( N + 1 ) ) );
% Diagonal entries.
D = D – diag ( sum ( D’ ) );
return
end neumann MATLAB Answers — New Questions
Write a function called get_distance that accepts two character vector inputs representing the names of two cities. The function returns the distance between them as an output argument called distance. For example, the call get_distance(‘Seattle, WA’
function distance = get_distance(x,y)
[~,~,raw] = xlsread(‘Distances.xlsx’);
col_labels = raw(1,:);
row_labels = raw(:,1);
try
distance = raw{contains(row_labels,y),contains(col_labels,x)};
catch
distance = -1;
end
end
error
Assessment result: incorrectNashville, TN and Las Vegas, NV
Variable distance has an incorrect value.
Assessment result: incorrectRandom city pairs
Variable distance has an incorrect value.
get_distance(‘Chattanooga, TN’,’Meads, KY’) returned -1 which is incorrect.function distance = get_distance(x,y)
[~,~,raw] = xlsread(‘Distances.xlsx’);
col_labels = raw(1,:);
row_labels = raw(:,1);
try
distance = raw{contains(row_labels,y),contains(col_labels,x)};
catch
distance = -1;
end
end
error
Assessment result: incorrectNashville, TN and Las Vegas, NV
Variable distance has an incorrect value.
Assessment result: incorrectRandom city pairs
Variable distance has an incorrect value.
get_distance(‘Chattanooga, TN’,’Meads, KY’) returned -1 which is incorrect. function distance = get_distance(x,y)
[~,~,raw] = xlsread(‘Distances.xlsx’);
col_labels = raw(1,:);
row_labels = raw(:,1);
try
distance = raw{contains(row_labels,y),contains(col_labels,x)};
catch
distance = -1;
end
end
error
Assessment result: incorrectNashville, TN and Las Vegas, NV
Variable distance has an incorrect value.
Assessment result: incorrectRandom city pairs
Variable distance has an incorrect value.
get_distance(‘Chattanooga, TN’,’Meads, KY’) returned -1 which is incorrect. homework, city distance, no more answers please! MATLAB Answers — New Questions
How can the best possible convergence be achieved between simulations in Ltspice and Simscape?
I am simulating the switching of a mosfet with an inductive and resistive load. When doing the simulations in Ltspice and Simscape and comparing them, it is observed that in the turning on of the mosfet (in the simulation in Simscape) a very high voltage peak appears with oscillation measured at the mosfet’s drain. In the Ltspice simulation, this peak is much smaller and does not present oscillation.
LTspice schematic
Ltspice simulation
Simscape schematic
Simscape simulationI am simulating the switching of a mosfet with an inductive and resistive load. When doing the simulations in Ltspice and Simscape and comparing them, it is observed that in the turning on of the mosfet (in the simulation in Simscape) a very high voltage peak appears with oscillation measured at the mosfet’s drain. In the Ltspice simulation, this peak is much smaller and does not present oscillation.
LTspice schematic
Ltspice simulation
Simscape schematic
Simscape simulation I am simulating the switching of a mosfet with an inductive and resistive load. When doing the simulations in Ltspice and Simscape and comparing them, it is observed that in the turning on of the mosfet (in the simulation in Simscape) a very high voltage peak appears with oscillation measured at the mosfet’s drain. In the Ltspice simulation, this peak is much smaller and does not present oscillation.
LTspice schematic
Ltspice simulation
Simscape schematic
Simscape simulation mismatch ltspice and simscape MATLAB Answers — New Questions
How to implement Extended Kalman Filter’s State Transition Function and Measurement Function for PMSM?
Hello, the TLDR of this post is that I am trying to learn how to implement a sensorless control for a 3 phase PMSM using the EKF Simulink block, but I can’t seem to make it work. I’m not sure if I implemented the State Transition Function or the Measurement Functions correctly.
The EKF Simulink block is set up as such
The equivalent Simulink implementation is as such
I have set the Covariance Matrix Q as NoiseMatrix(1:4) and Covariance Matrix R as NoiseMatrix(5:6) in the EKF block parameter below
StateTransitionFunction
The relevant state space equations of the 3 phase PMSM is derived as such
and I implemented the State Transition function as such
function x_next = pmsmStateTransition_3p(x,u)
% represents the dynaics of the PMSM and how the states of the …
% evolves over time
% x=[i_d; i_q; omega_e; theta_e] (state vector)
% u=[v_alpha; v_beta] (input vector)
% ——– Inputs ——– %
i_d=x(1);
i_q=x(2);
omega_e=x(3);
theta_e=x(4);
v_alpha=u(1);
v_beta=u(2);
% ——– Motor Parameters ——– %
R = 0.007184;
L = 19.5e-6;
pole_pairs = 6; %pole pairs
J = 3.37862;
B = 0;
lambda = 0.0623;
dt = 9e-5; % Ts
% ——– Equations ——– %
lambda_q = i_q*L;
lambda_d = i_d*L+lambda;
T_e = 3/2*pole_pairs*(i_q*(i_d*L + lambda) – i_d*i_q*L);
v_d = cos(theta_e)*v_alpha + sin(theta_e)*v_beta;
v_q = -sin(theta_e)*v_alpha + cos(theta_e)*v_beta;
% State Transition Equations
% Euler Discretization is used to calculate the next states
id_next = i_d + (v_d – R*i_d + omega_e*lambda_q)/L*dt;
iq_next = i_q + (v_q – R*i_q – omega_e*lambda_d)/L*dt;
omega_next = omega_e + (T_e – B*omega_e)/J*dt;
theta_next = theta_e + omega_e*dt;
% ——– Output ——– %
x_next=[id_next; iq_next; omega_next; theta_next];
end
Measurement Function
function y = pmsmMeasurement_3p(x)
% x=[i_d; i_q; omega_e; theta_e] (state vector)
% y=[i_alpha; i_beta] (output vector)
% ——— Inputs ———- %
i_d=x(1);
i_q=x(2);
theta_e=x(4);
% ——– Equations ——– %
i_alpha = i_d*cos(theta_e) – i_q*sin(theta_e);
i_beta = i_d*sin(theta_e) + i_q*cos(theta_e);
% ——— Output ———- %
y=[i_alpha; i_beta];
end
Results
I understand that the covariance matrices determines the results. After I set everything up, I would find the optimal values using the Genetic Algorithm, but even then the results from it don’t differ so much from the estimated we_hat in the bottom figure for results, so I just used a generic placeholder value of 100 for all values of the Noise Covariance Matrices (i.e. Q = [100, 100, 100, 100] and R = [100, 100]).
Have I implemented the functions properly? I would appreciate any help at all to help lessen the amount of things I need to debug. Thank you so much and I look forward to your reply.
I have attached all the relevant files in this post, so please let me know what you need and I can direct you to the relevant file.Hello, the TLDR of this post is that I am trying to learn how to implement a sensorless control for a 3 phase PMSM using the EKF Simulink block, but I can’t seem to make it work. I’m not sure if I implemented the State Transition Function or the Measurement Functions correctly.
The EKF Simulink block is set up as such
The equivalent Simulink implementation is as such
I have set the Covariance Matrix Q as NoiseMatrix(1:4) and Covariance Matrix R as NoiseMatrix(5:6) in the EKF block parameter below
StateTransitionFunction
The relevant state space equations of the 3 phase PMSM is derived as such
and I implemented the State Transition function as such
function x_next = pmsmStateTransition_3p(x,u)
% represents the dynaics of the PMSM and how the states of the …
% evolves over time
% x=[i_d; i_q; omega_e; theta_e] (state vector)
% u=[v_alpha; v_beta] (input vector)
% ——– Inputs ——– %
i_d=x(1);
i_q=x(2);
omega_e=x(3);
theta_e=x(4);
v_alpha=u(1);
v_beta=u(2);
% ——– Motor Parameters ——– %
R = 0.007184;
L = 19.5e-6;
pole_pairs = 6; %pole pairs
J = 3.37862;
B = 0;
lambda = 0.0623;
dt = 9e-5; % Ts
% ——– Equations ——– %
lambda_q = i_q*L;
lambda_d = i_d*L+lambda;
T_e = 3/2*pole_pairs*(i_q*(i_d*L + lambda) – i_d*i_q*L);
v_d = cos(theta_e)*v_alpha + sin(theta_e)*v_beta;
v_q = -sin(theta_e)*v_alpha + cos(theta_e)*v_beta;
% State Transition Equations
% Euler Discretization is used to calculate the next states
id_next = i_d + (v_d – R*i_d + omega_e*lambda_q)/L*dt;
iq_next = i_q + (v_q – R*i_q – omega_e*lambda_d)/L*dt;
omega_next = omega_e + (T_e – B*omega_e)/J*dt;
theta_next = theta_e + omega_e*dt;
% ——– Output ——– %
x_next=[id_next; iq_next; omega_next; theta_next];
end
Measurement Function
function y = pmsmMeasurement_3p(x)
% x=[i_d; i_q; omega_e; theta_e] (state vector)
% y=[i_alpha; i_beta] (output vector)
% ——— Inputs ———- %
i_d=x(1);
i_q=x(2);
theta_e=x(4);
% ——– Equations ——– %
i_alpha = i_d*cos(theta_e) – i_q*sin(theta_e);
i_beta = i_d*sin(theta_e) + i_q*cos(theta_e);
% ——— Output ———- %
y=[i_alpha; i_beta];
end
Results
I understand that the covariance matrices determines the results. After I set everything up, I would find the optimal values using the Genetic Algorithm, but even then the results from it don’t differ so much from the estimated we_hat in the bottom figure for results, so I just used a generic placeholder value of 100 for all values of the Noise Covariance Matrices (i.e. Q = [100, 100, 100, 100] and R = [100, 100]).
Have I implemented the functions properly? I would appreciate any help at all to help lessen the amount of things I need to debug. Thank you so much and I look forward to your reply.
I have attached all the relevant files in this post, so please let me know what you need and I can direct you to the relevant file. Hello, the TLDR of this post is that I am trying to learn how to implement a sensorless control for a 3 phase PMSM using the EKF Simulink block, but I can’t seem to make it work. I’m not sure if I implemented the State Transition Function or the Measurement Functions correctly.
The EKF Simulink block is set up as such
The equivalent Simulink implementation is as such
I have set the Covariance Matrix Q as NoiseMatrix(1:4) and Covariance Matrix R as NoiseMatrix(5:6) in the EKF block parameter below
StateTransitionFunction
The relevant state space equations of the 3 phase PMSM is derived as such
and I implemented the State Transition function as such
function x_next = pmsmStateTransition_3p(x,u)
% represents the dynaics of the PMSM and how the states of the …
% evolves over time
% x=[i_d; i_q; omega_e; theta_e] (state vector)
% u=[v_alpha; v_beta] (input vector)
% ——– Inputs ——– %
i_d=x(1);
i_q=x(2);
omega_e=x(3);
theta_e=x(4);
v_alpha=u(1);
v_beta=u(2);
% ——– Motor Parameters ——– %
R = 0.007184;
L = 19.5e-6;
pole_pairs = 6; %pole pairs
J = 3.37862;
B = 0;
lambda = 0.0623;
dt = 9e-5; % Ts
% ——– Equations ——– %
lambda_q = i_q*L;
lambda_d = i_d*L+lambda;
T_e = 3/2*pole_pairs*(i_q*(i_d*L + lambda) – i_d*i_q*L);
v_d = cos(theta_e)*v_alpha + sin(theta_e)*v_beta;
v_q = -sin(theta_e)*v_alpha + cos(theta_e)*v_beta;
% State Transition Equations
% Euler Discretization is used to calculate the next states
id_next = i_d + (v_d – R*i_d + omega_e*lambda_q)/L*dt;
iq_next = i_q + (v_q – R*i_q – omega_e*lambda_d)/L*dt;
omega_next = omega_e + (T_e – B*omega_e)/J*dt;
theta_next = theta_e + omega_e*dt;
% ——– Output ——– %
x_next=[id_next; iq_next; omega_next; theta_next];
end
Measurement Function
function y = pmsmMeasurement_3p(x)
% x=[i_d; i_q; omega_e; theta_e] (state vector)
% y=[i_alpha; i_beta] (output vector)
% ——— Inputs ———- %
i_d=x(1);
i_q=x(2);
theta_e=x(4);
% ——– Equations ——– %
i_alpha = i_d*cos(theta_e) – i_q*sin(theta_e);
i_beta = i_d*sin(theta_e) + i_q*cos(theta_e);
% ——— Output ———- %
y=[i_alpha; i_beta];
end
Results
I understand that the covariance matrices determines the results. After I set everything up, I would find the optimal values using the Genetic Algorithm, but even then the results from it don’t differ so much from the estimated we_hat in the bottom figure for results, so I just used a generic placeholder value of 100 for all values of the Noise Covariance Matrices (i.e. Q = [100, 100, 100, 100] and R = [100, 100]).
Have I implemented the functions properly? I would appreciate any help at all to help lessen the amount of things I need to debug. Thank you so much and I look forward to your reply.
I have attached all the relevant files in this post, so please let me know what you need and I can direct you to the relevant file. ekf, foc, pmsm, sensorless, state transition function, measurement function, simulink, r2023a MATLAB Answers — New Questions
Unstable 6 equation ode
Hello all, I am working on solving a 6 equation ODE to model the shape of a free surface in a channel. The paper that I am referencing only uses 5 euqations but i have no idea how they are solving for one of the variables so I added the variable and equation to the ODE. I have tried almost solver avalible in matlab and am very stuck on what to do next. Ive been in contact with the papers authors but they havent been a huge help. If anyone has a suggestion, it would be a huge help.
Here is the code:
clear; close all;
% Initial conditions and parameters
x0 = 0; %m
xfinal = 1; %m
h0 = 0.11; %m
hx0 = 0;
hxx0 = 0;
s0 = 1/163; % bottom slope
F1 = 1.07; % Froude number
N = 0.142857;
K = 2; % curvature
q = 0.12; % m^2 / s
g = 9.81; % gravity
k = 0;
theta = 0.00009;
beta0 = (1 + N)^2 / (1 + 2 * N);
ep0 = (h0 * hxx0) / (1 + hx0^2);
ep1 = hx0^2 / (1 + hx0^2);
S0 = (h0^2 / 2) + beta0 * (q^2 / (g * h0)) * (1 * ep0 * ((2 / (K + N + 2)) – ((1 – 2 * N) / (K + 2 * N + 2))) – ep1 * ((N + 1) / (N + 3)));
f0 = [h0; hx0; S0; theta; k;0];
% Solve the ODE
options = odeset(‘RelTol’,1e-5,’AbsTol’,1e-7);
[x, f] = ode23tb(@undularODE, [x0 xfinal], f0, options);
% Plot the results
figure;
plot(x, f);
legend(‘h’, ‘hx’, ‘S’, ‘theta’, ‘k’,’N’);
xlabel(‘x’);
ylabel(‘y’);
title(‘Solution’);
Here is the UdularODE function:
function dfdx = undularODE(x, f)
% Parameters
g = 9.81;
N = 0.142857;
q = 0.12; % m^2 / s
K = 2;
s0 = 1/163; % bottom slope
utheta = 1.1; % m/s velocity at momentum thickness
theta = f(4);
Nu = 1.12*10^-6; % kinematic viscosity
% Computed parameters
beta = (1 + N)^2 / (1 + 2 * N);
ep1 = f(2)^2 / (1 + f(2)^2); % epsilon 1
Re = 178458; % Reynolds number
Cf = 0.075 / (log(Re) – 2)^2; % skin friction coeff
ff = 4 * Cf * (1 + N)^2; % friction factor
sf = ff / 8 * (1 + 2 * (f(1) / 1)) * 1.47^2; % friction slope
Ue = (1 + N) * (q / f(1)); % max velocity at boundary layer edge
k = utheta / Ue;
H = (1.3 + 1.3 * (0.7 – k) + 3 * (0.7 – k)^2)^(2/3); % shape factor
Rtheta = (Ue * theta) / Nu; % momentum thickness Reynolds number
N2 = (H-1)/2; % calculated value of N
dUedx = -1*Ue*f(6)*(1+N2)*(Ue/f(1))*f(2);%dUedx
gamma = (theta / Ue) * dUedx * Rtheta^(1/4); % Buri Shape Factor
dHdx = (3*k^2 – 5.5*k + 3.68)^(2/3) * ( (1.46*(1-k^2))/( (1.5+k)*theta*Rtheta^(1/4)* (gamma +0.118*(0.67-k)) ) );
%dNdx(end+1)= 0.5*dHdx;
% Define the system of ODEs
hx = f(2);
eq2 = (((g * f(1)) / (beta * q^2)) * (f(3) – (f(1)^2 / 2)) – 1 + ep1 * ((N + 1) / (N + 3))) / …
((f(1) / (1 + f(2)^2)) * (2 / (K + N + 2)) – ((1 – 2 * N) / (K + 2 * N + 2)));
eq3 = f(1) * (s0 – sf);
eq4 = -1 * f(4)*((1 / (2 + 2 * N)) * (dHdx) – (1 / f(1)) * hx) * (H + 2) + Cf / 2;
eq5 = 1.46 * ((1 – f(5)^2) / ((1.5 + f(5)) * theta * Rtheta^(1/4))) * (gamma + 0.118 * (0.67 – f(5)));
eq6 = 0.5*dHdx;
% Return the derivatives
dfdx = [hx;
eq2;
eq3;
eq4;
eq5;
eq6];
%keyboard
endHello all, I am working on solving a 6 equation ODE to model the shape of a free surface in a channel. The paper that I am referencing only uses 5 euqations but i have no idea how they are solving for one of the variables so I added the variable and equation to the ODE. I have tried almost solver avalible in matlab and am very stuck on what to do next. Ive been in contact with the papers authors but they havent been a huge help. If anyone has a suggestion, it would be a huge help.
Here is the code:
clear; close all;
% Initial conditions and parameters
x0 = 0; %m
xfinal = 1; %m
h0 = 0.11; %m
hx0 = 0;
hxx0 = 0;
s0 = 1/163; % bottom slope
F1 = 1.07; % Froude number
N = 0.142857;
K = 2; % curvature
q = 0.12; % m^2 / s
g = 9.81; % gravity
k = 0;
theta = 0.00009;
beta0 = (1 + N)^2 / (1 + 2 * N);
ep0 = (h0 * hxx0) / (1 + hx0^2);
ep1 = hx0^2 / (1 + hx0^2);
S0 = (h0^2 / 2) + beta0 * (q^2 / (g * h0)) * (1 * ep0 * ((2 / (K + N + 2)) – ((1 – 2 * N) / (K + 2 * N + 2))) – ep1 * ((N + 1) / (N + 3)));
f0 = [h0; hx0; S0; theta; k;0];
% Solve the ODE
options = odeset(‘RelTol’,1e-5,’AbsTol’,1e-7);
[x, f] = ode23tb(@undularODE, [x0 xfinal], f0, options);
% Plot the results
figure;
plot(x, f);
legend(‘h’, ‘hx’, ‘S’, ‘theta’, ‘k’,’N’);
xlabel(‘x’);
ylabel(‘y’);
title(‘Solution’);
Here is the UdularODE function:
function dfdx = undularODE(x, f)
% Parameters
g = 9.81;
N = 0.142857;
q = 0.12; % m^2 / s
K = 2;
s0 = 1/163; % bottom slope
utheta = 1.1; % m/s velocity at momentum thickness
theta = f(4);
Nu = 1.12*10^-6; % kinematic viscosity
% Computed parameters
beta = (1 + N)^2 / (1 + 2 * N);
ep1 = f(2)^2 / (1 + f(2)^2); % epsilon 1
Re = 178458; % Reynolds number
Cf = 0.075 / (log(Re) – 2)^2; % skin friction coeff
ff = 4 * Cf * (1 + N)^2; % friction factor
sf = ff / 8 * (1 + 2 * (f(1) / 1)) * 1.47^2; % friction slope
Ue = (1 + N) * (q / f(1)); % max velocity at boundary layer edge
k = utheta / Ue;
H = (1.3 + 1.3 * (0.7 – k) + 3 * (0.7 – k)^2)^(2/3); % shape factor
Rtheta = (Ue * theta) / Nu; % momentum thickness Reynolds number
N2 = (H-1)/2; % calculated value of N
dUedx = -1*Ue*f(6)*(1+N2)*(Ue/f(1))*f(2);%dUedx
gamma = (theta / Ue) * dUedx * Rtheta^(1/4); % Buri Shape Factor
dHdx = (3*k^2 – 5.5*k + 3.68)^(2/3) * ( (1.46*(1-k^2))/( (1.5+k)*theta*Rtheta^(1/4)* (gamma +0.118*(0.67-k)) ) );
%dNdx(end+1)= 0.5*dHdx;
% Define the system of ODEs
hx = f(2);
eq2 = (((g * f(1)) / (beta * q^2)) * (f(3) – (f(1)^2 / 2)) – 1 + ep1 * ((N + 1) / (N + 3))) / …
((f(1) / (1 + f(2)^2)) * (2 / (K + N + 2)) – ((1 – 2 * N) / (K + 2 * N + 2)));
eq3 = f(1) * (s0 – sf);
eq4 = -1 * f(4)*((1 / (2 + 2 * N)) * (dHdx) – (1 / f(1)) * hx) * (H + 2) + Cf / 2;
eq5 = 1.46 * ((1 – f(5)^2) / ((1.5 + f(5)) * theta * Rtheta^(1/4))) * (gamma + 0.118 * (0.67 – f(5)));
eq6 = 0.5*dHdx;
% Return the derivatives
dfdx = [hx;
eq2;
eq3;
eq4;
eq5;
eq6];
%keyboard
end Hello all, I am working on solving a 6 equation ODE to model the shape of a free surface in a channel. The paper that I am referencing only uses 5 euqations but i have no idea how they are solving for one of the variables so I added the variable and equation to the ODE. I have tried almost solver avalible in matlab and am very stuck on what to do next. Ive been in contact with the papers authors but they havent been a huge help. If anyone has a suggestion, it would be a huge help.
Here is the code:
clear; close all;
% Initial conditions and parameters
x0 = 0; %m
xfinal = 1; %m
h0 = 0.11; %m
hx0 = 0;
hxx0 = 0;
s0 = 1/163; % bottom slope
F1 = 1.07; % Froude number
N = 0.142857;
K = 2; % curvature
q = 0.12; % m^2 / s
g = 9.81; % gravity
k = 0;
theta = 0.00009;
beta0 = (1 + N)^2 / (1 + 2 * N);
ep0 = (h0 * hxx0) / (1 + hx0^2);
ep1 = hx0^2 / (1 + hx0^2);
S0 = (h0^2 / 2) + beta0 * (q^2 / (g * h0)) * (1 * ep0 * ((2 / (K + N + 2)) – ((1 – 2 * N) / (K + 2 * N + 2))) – ep1 * ((N + 1) / (N + 3)));
f0 = [h0; hx0; S0; theta; k;0];
% Solve the ODE
options = odeset(‘RelTol’,1e-5,’AbsTol’,1e-7);
[x, f] = ode23tb(@undularODE, [x0 xfinal], f0, options);
% Plot the results
figure;
plot(x, f);
legend(‘h’, ‘hx’, ‘S’, ‘theta’, ‘k’,’N’);
xlabel(‘x’);
ylabel(‘y’);
title(‘Solution’);
Here is the UdularODE function:
function dfdx = undularODE(x, f)
% Parameters
g = 9.81;
N = 0.142857;
q = 0.12; % m^2 / s
K = 2;
s0 = 1/163; % bottom slope
utheta = 1.1; % m/s velocity at momentum thickness
theta = f(4);
Nu = 1.12*10^-6; % kinematic viscosity
% Computed parameters
beta = (1 + N)^2 / (1 + 2 * N);
ep1 = f(2)^2 / (1 + f(2)^2); % epsilon 1
Re = 178458; % Reynolds number
Cf = 0.075 / (log(Re) – 2)^2; % skin friction coeff
ff = 4 * Cf * (1 + N)^2; % friction factor
sf = ff / 8 * (1 + 2 * (f(1) / 1)) * 1.47^2; % friction slope
Ue = (1 + N) * (q / f(1)); % max velocity at boundary layer edge
k = utheta / Ue;
H = (1.3 + 1.3 * (0.7 – k) + 3 * (0.7 – k)^2)^(2/3); % shape factor
Rtheta = (Ue * theta) / Nu; % momentum thickness Reynolds number
N2 = (H-1)/2; % calculated value of N
dUedx = -1*Ue*f(6)*(1+N2)*(Ue/f(1))*f(2);%dUedx
gamma = (theta / Ue) * dUedx * Rtheta^(1/4); % Buri Shape Factor
dHdx = (3*k^2 – 5.5*k + 3.68)^(2/3) * ( (1.46*(1-k^2))/( (1.5+k)*theta*Rtheta^(1/4)* (gamma +0.118*(0.67-k)) ) );
%dNdx(end+1)= 0.5*dHdx;
% Define the system of ODEs
hx = f(2);
eq2 = (((g * f(1)) / (beta * q^2)) * (f(3) – (f(1)^2 / 2)) – 1 + ep1 * ((N + 1) / (N + 3))) / …
((f(1) / (1 + f(2)^2)) * (2 / (K + N + 2)) – ((1 – 2 * N) / (K + 2 * N + 2)));
eq3 = f(1) * (s0 – sf);
eq4 = -1 * f(4)*((1 / (2 + 2 * N)) * (dHdx) – (1 / f(1)) * hx) * (H + 2) + Cf / 2;
eq5 = 1.46 * ((1 – f(5)^2) / ((1.5 + f(5)) * theta * Rtheta^(1/4))) * (gamma + 0.118 * (0.67 – f(5)));
eq6 = 0.5*dHdx;
% Return the derivatives
dfdx = [hx;
eq2;
eq3;
eq4;
eq5;
eq6];
%keyboard
end fluid, ode, ode45, unstable MATLAB Answers — New Questions
How do I get the fft from the audio wav file?
Hi guys, I am new to MATLAB. I need help on how to get FFT plot from an audio file that i have?Hi guys, I am new to MATLAB. I need help on how to get FFT plot from an audio file that i have? Hi guys, I am new to MATLAB. I need help on how to get FFT plot from an audio file that i have? audioread noise fast fourier MATLAB Answers — New Questions
I/Q modulator
Hello,
Is there a way to drive the I/Q modulator tool in the RF blockset with an I/Q data file instead of a sinewave?
thansk,Hello,
Is there a way to drive the I/Q modulator tool in the RF blockset with an I/Q data file instead of a sinewave?
thansk, Hello,
Is there a way to drive the I/Q modulator tool in the RF blockset with an I/Q data file instead of a sinewave?
thansk, rf modulation, rf blockset, i/q data file, rf upconverter MATLAB Answers — New Questions
Battery switch to grid
Hi, I have a rather simple model with a battery, an dynamical load and a source representing the grid. Now I want the battery to shut off at 20%. I am using two ideal switches for it but I just cannot seem to get it to work. The battery is discharging but it does not stop at 20%.Hi, I have a rather simple model with a battery, an dynamical load and a source representing the grid. Now I want the battery to shut off at 20%. I am using two ideal switches for it but I just cannot seem to get it to work. The battery is discharging but it does not stop at 20%. Hi, I have a rather simple model with a battery, an dynamical load and a source representing the grid. Now I want the battery to shut off at 20%. I am using two ideal switches for it but I just cannot seem to get it to work. The battery is discharging but it does not stop at 20%. battery_system_management, switch MATLAB Answers — New Questions
GPU coder error with Nivida Jetson device
I am using the Matlab 2023b, I have no issue to compile the InceptionV3 classification to the Nvidia Jetson orin 32 GB. Now I got NVIDIA JETSON ORIN 64 BIT, I compiled the executable using GPU coder. I got issue. I upgraded matlab to 2024b, I have the same issue.
i am using the following codes
opencv_linkflags = ‘`pkg-config –cflags –libs opencv4`’;
coder.updateBuildInfo(‘addLinkFlags’,opencv_linkflags);
coder.updateBuildInfo(‘addIncludePaths’, ‘/usr/include/opencv4/’); %both remove or add this line, the GPU coder compilation process does not work.
fatal error: opencv2/imgproc/imgproc.hpp: No such file or directory
57 | #include <opencv2/imgproc/imgproc.hpp>
Any idea to help solve the issue?I am using the Matlab 2023b, I have no issue to compile the InceptionV3 classification to the Nvidia Jetson orin 32 GB. Now I got NVIDIA JETSON ORIN 64 BIT, I compiled the executable using GPU coder. I got issue. I upgraded matlab to 2024b, I have the same issue.
i am using the following codes
opencv_linkflags = ‘`pkg-config –cflags –libs opencv4`’;
coder.updateBuildInfo(‘addLinkFlags’,opencv_linkflags);
coder.updateBuildInfo(‘addIncludePaths’, ‘/usr/include/opencv4/’); %both remove or add this line, the GPU coder compilation process does not work.
fatal error: opencv2/imgproc/imgproc.hpp: No such file or directory
57 | #include <opencv2/imgproc/imgproc.hpp>
Any idea to help solve the issue? I am using the Matlab 2023b, I have no issue to compile the InceptionV3 classification to the Nvidia Jetson orin 32 GB. Now I got NVIDIA JETSON ORIN 64 BIT, I compiled the executable using GPU coder. I got issue. I upgraded matlab to 2024b, I have the same issue.
i am using the following codes
opencv_linkflags = ‘`pkg-config –cflags –libs opencv4`’;
coder.updateBuildInfo(‘addLinkFlags’,opencv_linkflags);
coder.updateBuildInfo(‘addIncludePaths’, ‘/usr/include/opencv4/’); %both remove or add this line, the GPU coder compilation process does not work.
fatal error: opencv2/imgproc/imgproc.hpp: No such file or directory
57 | #include <opencv2/imgproc/imgproc.hpp>
Any idea to help solve the issue? gpu coder, nvidia jetson MATLAB Answers — New Questions
Test coverage report shows same condition with 2 different sets of coverage stats
In the coverage report, it lists a condition under decisisions analyzed (example: if A > x) with the 2 possible outcomes true and false, with the totals for each true and false. However it then lists that identical condition a 2nd time with different totals for the outcomes again.
A visual example of the table that shows:
Decisions Analyzed:
What is the difference between the first set of 3 (labeled as 50% covered) and the second set of 230 (labeled as 100% covered)? This issue is present for every condition in my model. It is also what occurs for other coverage types, like MCDC. Here’s an MCDC example:
Again, the top half is the identical text to the bottom half, but the bottom half shows 1 of the 3 rows red (so more coverage is complete) whereas the top half shows all 3 in red (missing more coverage). What is the difference between the halves?
Thank you.
CodyIn the coverage report, it lists a condition under decisisions analyzed (example: if A > x) with the 2 possible outcomes true and false, with the totals for each true and false. However it then lists that identical condition a 2nd time with different totals for the outcomes again.
A visual example of the table that shows:
Decisions Analyzed:
What is the difference between the first set of 3 (labeled as 50% covered) and the second set of 230 (labeled as 100% covered)? This issue is present for every condition in my model. It is also what occurs for other coverage types, like MCDC. Here’s an MCDC example:
Again, the top half is the identical text to the bottom half, but the bottom half shows 1 of the 3 rows red (so more coverage is complete) whereas the top half shows all 3 in red (missing more coverage). What is the difference between the halves?
Thank you.
Cody In the coverage report, it lists a condition under decisisions analyzed (example: if A > x) with the 2 possible outcomes true and false, with the totals for each true and false. However it then lists that identical condition a 2nd time with different totals for the outcomes again.
A visual example of the table that shows:
Decisions Analyzed:
What is the difference between the first set of 3 (labeled as 50% covered) and the second set of 230 (labeled as 100% covered)? This issue is present for every condition in my model. It is also what occurs for other coverage types, like MCDC. Here’s an MCDC example:
Again, the top half is the identical text to the bottom half, but the bottom half shows 1 of the 3 rows red (so more coverage is complete) whereas the top half shows all 3 in red (missing more coverage). What is the difference between the halves?
Thank you.
Cody test coverage, double reported test coverage, mcdc, decision, coverage report MATLAB Answers — New Questions
Algebraic loop in MRAC discrete model
Hello everyone.
I have this system I built that represents an RMAC model
After the system worked continuously as it should, I converted it to discrete with a sampling time of 0.01
I get an error that the system enters an algebraic loop and I am unable to converge to the desired values. (The output of the system is increased to very, very high values)
I tried to put a unit delay but it neither helps nor leads to entertainment
what can be done? I would really appreciate some help.. I tried everything possible
Also, should I change the sampling time of each block to 0.01 or is it ok to leave -1?
Many thanks to everyone who helps
errors:
Error:’sim2/discrete plant2′ or the model referenced by it contains a block that updates persistent or state variables while computing outputs and is not supported in an algebraic loop. It is in an algebraic loop with the following blocks.
Error:Input ports (1) of ‘sim2/Adaptive Mechanism_known parameters_ discrete2/MATLAB Function1’ are involved in the loop.
and more..Hello everyone.
I have this system I built that represents an RMAC model
After the system worked continuously as it should, I converted it to discrete with a sampling time of 0.01
I get an error that the system enters an algebraic loop and I am unable to converge to the desired values. (The output of the system is increased to very, very high values)
I tried to put a unit delay but it neither helps nor leads to entertainment
what can be done? I would really appreciate some help.. I tried everything possible
Also, should I change the sampling time of each block to 0.01 or is it ok to leave -1?
Many thanks to everyone who helps
errors:
Error:’sim2/discrete plant2′ or the model referenced by it contains a block that updates persistent or state variables while computing outputs and is not supported in an algebraic loop. It is in an algebraic loop with the following blocks.
Error:Input ports (1) of ‘sim2/Adaptive Mechanism_known parameters_ discrete2/MATLAB Function1’ are involved in the loop.
and more.. Hello everyone.
I have this system I built that represents an RMAC model
After the system worked continuously as it should, I converted it to discrete with a sampling time of 0.01
I get an error that the system enters an algebraic loop and I am unable to converge to the desired values. (The output of the system is increased to very, very high values)
I tried to put a unit delay but it neither helps nor leads to entertainment
what can be done? I would really appreciate some help.. I tried everything possible
Also, should I change the sampling time of each block to 0.01 or is it ok to leave -1?
Many thanks to everyone who helps
errors:
Error:’sim2/discrete plant2′ or the model referenced by it contains a block that updates persistent or state variables while computing outputs and is not supported in an algebraic loop. It is in an algebraic loop with the following blocks.
Error:Input ports (1) of ‘sim2/Adaptive Mechanism_known parameters_ discrete2/MATLAB Function1’ are involved in the loop.
and more.. algebraic loop, discrete time, sample time, controller, mrac MATLAB Answers — New Questions