Category: Matlab
Category Archives: Matlab
Regarding the GUI update to change the slider values.
Dear Friends Hello,
I have a querry I request to please help.
I have created a GUI where the values is gratting is selected from the ‘select_gratting’ as shownin attached figure. I want to change the slider limits based on gratting selected. For example currently it shows – 30 to 550 for 1200 gratting values, but when 2400 gratting selected I want slider limit to change and show 30 to 250 without closing the GUI.
I request to please help, how can I do this.
Thanking you,
Kind regardsDear Friends Hello,
I have a querry I request to please help.
I have created a GUI where the values is gratting is selected from the ‘select_gratting’ as shownin attached figure. I want to change the slider limits based on gratting selected. For example currently it shows – 30 to 550 for 1200 gratting values, but when 2400 gratting selected I want slider limit to change and show 30 to 250 without closing the GUI.
I request to please help, how can I do this.
Thanking you,
Kind regards Dear Friends Hello,
I have a querry I request to please help.
I have created a GUI where the values is gratting is selected from the ‘select_gratting’ as shownin attached figure. I want to change the slider limits based on gratting selected. For example currently it shows – 30 to 550 for 1200 gratting values, but when 2400 gratting selected I want slider limit to change and show 30 to 250 without closing the GUI.
I request to please help, how can I do this.
Thanking you,
Kind regards gui, matlab, slider MATLAB Answers — New Questions
Shapefile not overlapping perfectly over pcolor plot
I am trying to plot a pcolor plot for Sea surface temperature data set and to represent the coastaline in the plot i have downloadwed global coastline shapefile and when i am using geoshow to read and overlay on the pcolor plot it is not matching perfectlyI am trying to plot a pcolor plot for Sea surface temperature data set and to represent the coastaline in the plot i have downloadwed global coastline shapefile and when i am using geoshow to read and overlay on the pcolor plot it is not matching perfectly I am trying to plot a pcolor plot for Sea surface temperature data set and to represent the coastaline in the plot i have downloadwed global coastline shapefile and when i am using geoshow to read and overlay on the pcolor plot it is not matching perfectly geoshow, shapefile, pcolor plot MATLAB Answers — New Questions
Plotting a 3d hydrogen atomic orbital plot from a data file
I have a data file of two colums, column1 has data of radial coordinate ‘r’ and column2 has data of ‘wavefunction’ of 3d orbital both are 1D arrays of each 45 entries. I need to obtain a 3D plot in cartesian coordinates ‘wavefunction(x,y,z)’ after multiplying the corresponding spherical harmonic functions of 3dz^2. How to get one. I am very new to MATLAB any help would be appreciated.
The data is as follows:
0.00 0.000000
0.45 0.000627
0.90 0.002467
1.35 0.005404
1.80 0.009263
2.25 0.013828
2.70 0.018859
3.15 0.024107
3.60 0.029329
4.05 0.034296
4.50 0.038798
4.95 0.042653
5.40 0.045707
5.85 0.047850
6.30 0.049018
6.75 0.049205
7.20 0.048467
7.65 0.046926
8.10 0.044759
8.55 0.042183
9.00 0.039422
9.45 0.036660
9.90 0.033972
10.35 0.031248
10.80 0.028078
11.25 0.023511
11.70 0.016026
12.15 0.005061
12.60 -.006867
13.05 -.014665
13.50 -.014647
13.95 -.007211
14.40 0.003441
14.85 0.011842
15.30 0.015687
15.75 0.016839
16.20 0.016349
16.65 0.014982
17.10 0.013238
17.55 0.011416
18.00 0.009680
18.45 0.008110
18.90 0.006736
19.35 0.005560
19.80 0.004567I have a data file of two colums, column1 has data of radial coordinate ‘r’ and column2 has data of ‘wavefunction’ of 3d orbital both are 1D arrays of each 45 entries. I need to obtain a 3D plot in cartesian coordinates ‘wavefunction(x,y,z)’ after multiplying the corresponding spherical harmonic functions of 3dz^2. How to get one. I am very new to MATLAB any help would be appreciated.
The data is as follows:
0.00 0.000000
0.45 0.000627
0.90 0.002467
1.35 0.005404
1.80 0.009263
2.25 0.013828
2.70 0.018859
3.15 0.024107
3.60 0.029329
4.05 0.034296
4.50 0.038798
4.95 0.042653
5.40 0.045707
5.85 0.047850
6.30 0.049018
6.75 0.049205
7.20 0.048467
7.65 0.046926
8.10 0.044759
8.55 0.042183
9.00 0.039422
9.45 0.036660
9.90 0.033972
10.35 0.031248
10.80 0.028078
11.25 0.023511
11.70 0.016026
12.15 0.005061
12.60 -.006867
13.05 -.014665
13.50 -.014647
13.95 -.007211
14.40 0.003441
14.85 0.011842
15.30 0.015687
15.75 0.016839
16.20 0.016349
16.65 0.014982
17.10 0.013238
17.55 0.011416
18.00 0.009680
18.45 0.008110
18.90 0.006736
19.35 0.005560
19.80 0.004567 I have a data file of two colums, column1 has data of radial coordinate ‘r’ and column2 has data of ‘wavefunction’ of 3d orbital both are 1D arrays of each 45 entries. I need to obtain a 3D plot in cartesian coordinates ‘wavefunction(x,y,z)’ after multiplying the corresponding spherical harmonic functions of 3dz^2. How to get one. I am very new to MATLAB any help would be appreciated.
The data is as follows:
0.00 0.000000
0.45 0.000627
0.90 0.002467
1.35 0.005404
1.80 0.009263
2.25 0.013828
2.70 0.018859
3.15 0.024107
3.60 0.029329
4.05 0.034296
4.50 0.038798
4.95 0.042653
5.40 0.045707
5.85 0.047850
6.30 0.049018
6.75 0.049205
7.20 0.048467
7.65 0.046926
8.10 0.044759
8.55 0.042183
9.00 0.039422
9.45 0.036660
9.90 0.033972
10.35 0.031248
10.80 0.028078
11.25 0.023511
11.70 0.016026
12.15 0.005061
12.60 -.006867
13.05 -.014665
13.50 -.014647
13.95 -.007211
14.40 0.003441
14.85 0.011842
15.30 0.015687
15.75 0.016839
16.20 0.016349
16.65 0.014982
17.10 0.013238
17.55 0.011416
18.00 0.009680
18.45 0.008110
18.90 0.006736
19.35 0.005560
19.80 0.004567 3dz^2 orbital plot MATLAB Answers — New Questions
sltest.harness.create function input ‘source’ can’t be set ‘Signal Builder’ in parameter pairs in matlab 2022b
sltest.harness.create(‘Harness_Test’,’Source’,’Signal editor’,’Sink’,’Outport’);
error:
Expected input to match one of these values:
‘Inport’, ‘Signal Editor’, ‘From Workspace’, ‘From File’, ‘Test Sequence’, ‘Chart’, ‘Constant’, ‘Ground’, ‘None’, ‘Custom’
The input, ‘Signal Builder’, did not match any of the valid values.
This means I can’t assign ‘Signal Builder’ to ‘Source’, matlab version is 2022b, but there is no error in 2022a(Tested many times).
Is this issue related to matlab version and how to solve it? Still need to use ‘Signal Builder’.sltest.harness.create(‘Harness_Test’,’Source’,’Signal editor’,’Sink’,’Outport’);
error:
Expected input to match one of these values:
‘Inport’, ‘Signal Editor’, ‘From Workspace’, ‘From File’, ‘Test Sequence’, ‘Chart’, ‘Constant’, ‘Ground’, ‘None’, ‘Custom’
The input, ‘Signal Builder’, did not match any of the valid values.
This means I can’t assign ‘Signal Builder’ to ‘Source’, matlab version is 2022b, but there is no error in 2022a(Tested many times).
Is this issue related to matlab version and how to solve it? Still need to use ‘Signal Builder’. sltest.harness.create(‘Harness_Test’,’Source’,’Signal editor’,’Sink’,’Outport’);
error:
Expected input to match one of these values:
‘Inport’, ‘Signal Editor’, ‘From Workspace’, ‘From File’, ‘Test Sequence’, ‘Chart’, ‘Constant’, ‘Ground’, ‘None’, ‘Custom’
The input, ‘Signal Builder’, did not match any of the valid values.
This means I can’t assign ‘Signal Builder’ to ‘Source’, matlab version is 2022b, but there is no error in 2022a(Tested many times).
Is this issue related to matlab version and how to solve it? Still need to use ‘Signal Builder’. sltest.harness.create MATLAB Answers — New Questions
How do I solve this error in Parameter Setting for 2-D Lookup Table Block in Simulink?
I’m trying to create a surrogate model for vehicle dynamics in Simulink, but I’m encountering an error when setting parameters for the 2-D Lookup Table block. I would greatly appreciate any advice.
When executing the following code, this error occurs.
set_param([modelName ‘/SurrogateModel’], …
‘RowIndex’, mat2str(throttleBreakpoints), …
‘ColumnIndex’, mat2str(brakeBreakpoints), …
‘Table’, mat2str(speedData));
Error message:
There is no parameter named ‘RowIndex’ in the Lookup_n-D block
I can’t figure out how I can solve this kind of error.
I was wondering if you could give me a solution.
How should I modify the code?
Here is my matlab script to create the surrogate model.
Full Script
% Create a surrogate model for vehicle longitudinal dynamics
% Set model name
modelName = ‘VehicleLongitudinalSurrogate’;
% Create new Simulink model
new_system(modelName);
open_system(modelName);
% Input: Throttle position (0-100%)
add_block(‘simulink/Sources/In1’, [modelName ‘/Throttle’]);
set_param([modelName ‘/Throttle’], ‘Position’, [100, 100, 130, 130]);
% Input: Brake pressure (0-100%)
add_block(‘simulink/Sources/In1’, [modelName ‘/Brake’]);
set_param([modelName ‘/Brake’], ‘Position’, [100, 200, 130, 230]);
% Surrogate model (Lookup table)
add_block(‘simulink/Lookup Tables/2-D Lookup Table’, [modelName ‘/SurrogateModel’]);
set_param([modelName ‘/SurrogateModel’], ‘Position’, [250, 140, 350, 190]);
% Output: Vehicle speed (km/h)
add_block(‘simulink/Sinks/Out1’, [modelName ‘/Speed’]);
set_param([modelName ‘/Speed’], ‘Position’, [450, 160, 480, 190]);
% Connect blocks
add_line(modelName, ‘Throttle/1’, ‘SurrogateModel/1’, ‘autorouting’, ‘on’);
add_line(modelName, ‘Brake/1’, ‘SurrogateModel/2’, ‘autorouting’, ‘on’);
add_line(modelName, ‘SurrogateModel/1’, ‘Speed/1’, ‘autorouting’, ‘on’);
% Set lookup table parameters (simplified data)
throttleBreakpoints = 0:20:100;
brakeBreakpoints = 0:20:100;
speedData = [
120, 100, 80, 60, 40, 20;
100, 80, 60, 40, 20, 0;
80, 60, 40, 20, 0, 0;
60, 40, 20, 0, 0, 0;
40, 20, 0, 0, 0, 0;
20, 0, 0, 0, 0, 0
];
% Set parameters (this is where the error occurs)
set_param([modelName ‘/SurrogateModel’], …
‘RowIndex’, mat2str(throttleBreakpoints), …
‘ColumnIndex’, mat2str(brakeBreakpoints), …
‘Table’, mat2str(speedData));
% Save and close the model
save_system(modelName, [modelName ‘.slx’]);
close_system(modelName);
disp(‘Vehicle longitudinal dynamics surrogate model has been created and saved.’);
Best,I’m trying to create a surrogate model for vehicle dynamics in Simulink, but I’m encountering an error when setting parameters for the 2-D Lookup Table block. I would greatly appreciate any advice.
When executing the following code, this error occurs.
set_param([modelName ‘/SurrogateModel’], …
‘RowIndex’, mat2str(throttleBreakpoints), …
‘ColumnIndex’, mat2str(brakeBreakpoints), …
‘Table’, mat2str(speedData));
Error message:
There is no parameter named ‘RowIndex’ in the Lookup_n-D block
I can’t figure out how I can solve this kind of error.
I was wondering if you could give me a solution.
How should I modify the code?
Here is my matlab script to create the surrogate model.
Full Script
% Create a surrogate model for vehicle longitudinal dynamics
% Set model name
modelName = ‘VehicleLongitudinalSurrogate’;
% Create new Simulink model
new_system(modelName);
open_system(modelName);
% Input: Throttle position (0-100%)
add_block(‘simulink/Sources/In1’, [modelName ‘/Throttle’]);
set_param([modelName ‘/Throttle’], ‘Position’, [100, 100, 130, 130]);
% Input: Brake pressure (0-100%)
add_block(‘simulink/Sources/In1’, [modelName ‘/Brake’]);
set_param([modelName ‘/Brake’], ‘Position’, [100, 200, 130, 230]);
% Surrogate model (Lookup table)
add_block(‘simulink/Lookup Tables/2-D Lookup Table’, [modelName ‘/SurrogateModel’]);
set_param([modelName ‘/SurrogateModel’], ‘Position’, [250, 140, 350, 190]);
% Output: Vehicle speed (km/h)
add_block(‘simulink/Sinks/Out1’, [modelName ‘/Speed’]);
set_param([modelName ‘/Speed’], ‘Position’, [450, 160, 480, 190]);
% Connect blocks
add_line(modelName, ‘Throttle/1’, ‘SurrogateModel/1’, ‘autorouting’, ‘on’);
add_line(modelName, ‘Brake/1’, ‘SurrogateModel/2’, ‘autorouting’, ‘on’);
add_line(modelName, ‘SurrogateModel/1’, ‘Speed/1’, ‘autorouting’, ‘on’);
% Set lookup table parameters (simplified data)
throttleBreakpoints = 0:20:100;
brakeBreakpoints = 0:20:100;
speedData = [
120, 100, 80, 60, 40, 20;
100, 80, 60, 40, 20, 0;
80, 60, 40, 20, 0, 0;
60, 40, 20, 0, 0, 0;
40, 20, 0, 0, 0, 0;
20, 0, 0, 0, 0, 0
];
% Set parameters (this is where the error occurs)
set_param([modelName ‘/SurrogateModel’], …
‘RowIndex’, mat2str(throttleBreakpoints), …
‘ColumnIndex’, mat2str(brakeBreakpoints), …
‘Table’, mat2str(speedData));
% Save and close the model
save_system(modelName, [modelName ‘.slx’]);
close_system(modelName);
disp(‘Vehicle longitudinal dynamics surrogate model has been created and saved.’);
Best, I’m trying to create a surrogate model for vehicle dynamics in Simulink, but I’m encountering an error when setting parameters for the 2-D Lookup Table block. I would greatly appreciate any advice.
When executing the following code, this error occurs.
set_param([modelName ‘/SurrogateModel’], …
‘RowIndex’, mat2str(throttleBreakpoints), …
‘ColumnIndex’, mat2str(brakeBreakpoints), …
‘Table’, mat2str(speedData));
Error message:
There is no parameter named ‘RowIndex’ in the Lookup_n-D block
I can’t figure out how I can solve this kind of error.
I was wondering if you could give me a solution.
How should I modify the code?
Here is my matlab script to create the surrogate model.
Full Script
% Create a surrogate model for vehicle longitudinal dynamics
% Set model name
modelName = ‘VehicleLongitudinalSurrogate’;
% Create new Simulink model
new_system(modelName);
open_system(modelName);
% Input: Throttle position (0-100%)
add_block(‘simulink/Sources/In1’, [modelName ‘/Throttle’]);
set_param([modelName ‘/Throttle’], ‘Position’, [100, 100, 130, 130]);
% Input: Brake pressure (0-100%)
add_block(‘simulink/Sources/In1’, [modelName ‘/Brake’]);
set_param([modelName ‘/Brake’], ‘Position’, [100, 200, 130, 230]);
% Surrogate model (Lookup table)
add_block(‘simulink/Lookup Tables/2-D Lookup Table’, [modelName ‘/SurrogateModel’]);
set_param([modelName ‘/SurrogateModel’], ‘Position’, [250, 140, 350, 190]);
% Output: Vehicle speed (km/h)
add_block(‘simulink/Sinks/Out1’, [modelName ‘/Speed’]);
set_param([modelName ‘/Speed’], ‘Position’, [450, 160, 480, 190]);
% Connect blocks
add_line(modelName, ‘Throttle/1’, ‘SurrogateModel/1’, ‘autorouting’, ‘on’);
add_line(modelName, ‘Brake/1’, ‘SurrogateModel/2’, ‘autorouting’, ‘on’);
add_line(modelName, ‘SurrogateModel/1’, ‘Speed/1’, ‘autorouting’, ‘on’);
% Set lookup table parameters (simplified data)
throttleBreakpoints = 0:20:100;
brakeBreakpoints = 0:20:100;
speedData = [
120, 100, 80, 60, 40, 20;
100, 80, 60, 40, 20, 0;
80, 60, 40, 20, 0, 0;
60, 40, 20, 0, 0, 0;
40, 20, 0, 0, 0, 0;
20, 0, 0, 0, 0, 0
];
% Set parameters (this is where the error occurs)
set_param([modelName ‘/SurrogateModel’], …
‘RowIndex’, mat2str(throttleBreakpoints), …
‘ColumnIndex’, mat2str(brakeBreakpoints), …
‘Table’, mat2str(speedData));
% Save and close the model
save_system(modelName, [modelName ‘.slx’]);
close_system(modelName);
disp(‘Vehicle longitudinal dynamics surrogate model has been created and saved.’);
Best, simulink, matlab code MATLAB Answers — New Questions
Speed up numeric integral
Hi,everyone.I got a problem of doing numeric integral on the matrix H (which is at the bottom part of my code).
The code works fine but I would like to speed it up? Am I doing something stupid to make it slow?Thanks for your help.
clear
L=0.1;
section=50;
a=L./2;
b=L./section;
v=3e8;
f1=1.2e9;
f2=4.8e9;
f3=7.5e9;
f4=10e9;
w1=(2.*pi.*f1);
w2=(2.*pi.*f2);
w3=(2.*pi.*f3);
w4=(2.*pi.*f4);
Z01=50;
Z02=75;
a0=(log(Z02./Z01))./(2..*L);
T=a;
Ub=a;
Lb=-a;
ub=a;
lb=-a;
k=5;
syms x y w m
%%% Revised Algorithm
l=0:(2.*L)./(2.*k):L % Approximate sections dvided
% Approximate terms
sec=numel(l)-1;
Z1=[50 55 60 65 70 80 75]; % Set the impedance of the end of each sections
ac=10; % Choose the accuracy of dividing a section
for s=1:1:sec
c=(l(s+1)-l(s))./ac;
app_cos=0.5./ac.*log(Z1(s+1)./Z1(s)).*sin(ac./2.*(w./v).*c).*cos(((ac+1)./2).*(w./v).*c)./sin(((c.*w)./(2.*v)));
app_sin=0.5./ac.*log(Z1(s+1)./Z1(s)).*sin(ac./2.*(w./v).*c).*sin(((ac+1)./2).*(w./v).*c)./sin(((c.*w)./(2.*v)));
amp=0.75;
Ga(s)=(app_cos-(1i.*amp.*app_sin));
end
Ta=(1-(abs(Ga(1:1:end)).^2));
%%% Turn closed loop terms into matrix presentation
for t=1:1:sec
for r=1:1:sec
E(t,r)=Ga(t).*Ga(r);
end
end
E=triu(E,1);
for t=1:1:sec
for r=1:1:sec
D(t,r)=abs(E(r,t));
end
end
C1=sum(D);
% Construct approximate loop terms
for t=1:1:sec
D1(t)=prod(Ta(1:t))./(1+(sum(C1(1:t))));
end
D=[1 D1(2:end)];
Dm=transpose(D).*D;
% Cmn
m=transpose(1:5);
n=1:5;
g=(v.^2.*w.^2.*cos((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*m.*x).*cos(20.*sym(pi).*n.*y) + 10.*sym(pi).*m.*v.^3.*w.*sin(20.*sym(pi).*m.*x).*sin((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*n.*y) – 10.*sym(pi).*n.*v.^3.*w.*sin(20.*sym(pi).*n.*y).*sin((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*m.*x) + 100.*m.*n.*v.^4.*sym(pi).^2.*sin(20.*sym(pi).*m.*x).*sin(20.*sym(pi).*n.*y).*cos((2.*w.*(- y + x))./v))./(4.*(w.^2 – 100.*sym(pi).^2.*m.^2.*v.^2).*(w.^2 – 100.*sym(pi).^2.*n.^2.*v.^2));
for p=1:numel(l)-1
x1=l(p);
x2=l(p+1);
for q=1:numel(l)-1
y1=l(q);
y2=l(p+1);
Ht{p,q}=matlabFunction(((subs(g,[x y],[x2 y2])-subs(g,[x y],[x1 y1]))*Dm(p,q)));
end
end
Hi=Ht{1};
for m=2:1:numel(Ht)
Hi=Hi+vpa(Ht{m},3);
end
H=integral(Hi,w1,w2,"ArrayValued",true)Hi,everyone.I got a problem of doing numeric integral on the matrix H (which is at the bottom part of my code).
The code works fine but I would like to speed it up? Am I doing something stupid to make it slow?Thanks for your help.
clear
L=0.1;
section=50;
a=L./2;
b=L./section;
v=3e8;
f1=1.2e9;
f2=4.8e9;
f3=7.5e9;
f4=10e9;
w1=(2.*pi.*f1);
w2=(2.*pi.*f2);
w3=(2.*pi.*f3);
w4=(2.*pi.*f4);
Z01=50;
Z02=75;
a0=(log(Z02./Z01))./(2..*L);
T=a;
Ub=a;
Lb=-a;
ub=a;
lb=-a;
k=5;
syms x y w m
%%% Revised Algorithm
l=0:(2.*L)./(2.*k):L % Approximate sections dvided
% Approximate terms
sec=numel(l)-1;
Z1=[50 55 60 65 70 80 75]; % Set the impedance of the end of each sections
ac=10; % Choose the accuracy of dividing a section
for s=1:1:sec
c=(l(s+1)-l(s))./ac;
app_cos=0.5./ac.*log(Z1(s+1)./Z1(s)).*sin(ac./2.*(w./v).*c).*cos(((ac+1)./2).*(w./v).*c)./sin(((c.*w)./(2.*v)));
app_sin=0.5./ac.*log(Z1(s+1)./Z1(s)).*sin(ac./2.*(w./v).*c).*sin(((ac+1)./2).*(w./v).*c)./sin(((c.*w)./(2.*v)));
amp=0.75;
Ga(s)=(app_cos-(1i.*amp.*app_sin));
end
Ta=(1-(abs(Ga(1:1:end)).^2));
%%% Turn closed loop terms into matrix presentation
for t=1:1:sec
for r=1:1:sec
E(t,r)=Ga(t).*Ga(r);
end
end
E=triu(E,1);
for t=1:1:sec
for r=1:1:sec
D(t,r)=abs(E(r,t));
end
end
C1=sum(D);
% Construct approximate loop terms
for t=1:1:sec
D1(t)=prod(Ta(1:t))./(1+(sum(C1(1:t))));
end
D=[1 D1(2:end)];
Dm=transpose(D).*D;
% Cmn
m=transpose(1:5);
n=1:5;
g=(v.^2.*w.^2.*cos((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*m.*x).*cos(20.*sym(pi).*n.*y) + 10.*sym(pi).*m.*v.^3.*w.*sin(20.*sym(pi).*m.*x).*sin((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*n.*y) – 10.*sym(pi).*n.*v.^3.*w.*sin(20.*sym(pi).*n.*y).*sin((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*m.*x) + 100.*m.*n.*v.^4.*sym(pi).^2.*sin(20.*sym(pi).*m.*x).*sin(20.*sym(pi).*n.*y).*cos((2.*w.*(- y + x))./v))./(4.*(w.^2 – 100.*sym(pi).^2.*m.^2.*v.^2).*(w.^2 – 100.*sym(pi).^2.*n.^2.*v.^2));
for p=1:numel(l)-1
x1=l(p);
x2=l(p+1);
for q=1:numel(l)-1
y1=l(q);
y2=l(p+1);
Ht{p,q}=matlabFunction(((subs(g,[x y],[x2 y2])-subs(g,[x y],[x1 y1]))*Dm(p,q)));
end
end
Hi=Ht{1};
for m=2:1:numel(Ht)
Hi=Hi+vpa(Ht{m},3);
end
H=integral(Hi,w1,w2,"ArrayValued",true) Hi,everyone.I got a problem of doing numeric integral on the matrix H (which is at the bottom part of my code).
The code works fine but I would like to speed it up? Am I doing something stupid to make it slow?Thanks for your help.
clear
L=0.1;
section=50;
a=L./2;
b=L./section;
v=3e8;
f1=1.2e9;
f2=4.8e9;
f3=7.5e9;
f4=10e9;
w1=(2.*pi.*f1);
w2=(2.*pi.*f2);
w3=(2.*pi.*f3);
w4=(2.*pi.*f4);
Z01=50;
Z02=75;
a0=(log(Z02./Z01))./(2..*L);
T=a;
Ub=a;
Lb=-a;
ub=a;
lb=-a;
k=5;
syms x y w m
%%% Revised Algorithm
l=0:(2.*L)./(2.*k):L % Approximate sections dvided
% Approximate terms
sec=numel(l)-1;
Z1=[50 55 60 65 70 80 75]; % Set the impedance of the end of each sections
ac=10; % Choose the accuracy of dividing a section
for s=1:1:sec
c=(l(s+1)-l(s))./ac;
app_cos=0.5./ac.*log(Z1(s+1)./Z1(s)).*sin(ac./2.*(w./v).*c).*cos(((ac+1)./2).*(w./v).*c)./sin(((c.*w)./(2.*v)));
app_sin=0.5./ac.*log(Z1(s+1)./Z1(s)).*sin(ac./2.*(w./v).*c).*sin(((ac+1)./2).*(w./v).*c)./sin(((c.*w)./(2.*v)));
amp=0.75;
Ga(s)=(app_cos-(1i.*amp.*app_sin));
end
Ta=(1-(abs(Ga(1:1:end)).^2));
%%% Turn closed loop terms into matrix presentation
for t=1:1:sec
for r=1:1:sec
E(t,r)=Ga(t).*Ga(r);
end
end
E=triu(E,1);
for t=1:1:sec
for r=1:1:sec
D(t,r)=abs(E(r,t));
end
end
C1=sum(D);
% Construct approximate loop terms
for t=1:1:sec
D1(t)=prod(Ta(1:t))./(1+(sum(C1(1:t))));
end
D=[1 D1(2:end)];
Dm=transpose(D).*D;
% Cmn
m=transpose(1:5);
n=1:5;
g=(v.^2.*w.^2.*cos((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*m.*x).*cos(20.*sym(pi).*n.*y) + 10.*sym(pi).*m.*v.^3.*w.*sin(20.*sym(pi).*m.*x).*sin((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*n.*y) – 10.*sym(pi).*n.*v.^3.*w.*sin(20.*sym(pi).*n.*y).*sin((2.*w.*(- y + x))./v).*cos(20.*sym(pi).*m.*x) + 100.*m.*n.*v.^4.*sym(pi).^2.*sin(20.*sym(pi).*m.*x).*sin(20.*sym(pi).*n.*y).*cos((2.*w.*(- y + x))./v))./(4.*(w.^2 – 100.*sym(pi).^2.*m.^2.*v.^2).*(w.^2 – 100.*sym(pi).^2.*n.^2.*v.^2));
for p=1:numel(l)-1
x1=l(p);
x2=l(p+1);
for q=1:numel(l)-1
y1=l(q);
y2=l(p+1);
Ht{p,q}=matlabFunction(((subs(g,[x y],[x2 y2])-subs(g,[x y],[x1 y1]))*Dm(p,q)));
end
end
Hi=Ht{1};
for m=2:1:numel(Ht)
Hi=Hi+vpa(Ht{m},3);
end
H=integral(Hi,w1,w2,"ArrayValued",true) integral MATLAB Answers — New Questions
How to import JPK force maps?
Hello,
I am trying to import force maps data from JPK and I could not find any clue on how to begin. Could anyone help me with how I could import raw data from force map files? Any hints and ideas are appriciated. My plan is to fit the data myself in Matlab as the available programs do not offer good fitting methods. I have compressed a JPK force map file in .zip, so I could attach it here.Hello,
I am trying to import force maps data from JPK and I could not find any clue on how to begin. Could anyone help me with how I could import raw data from force map files? Any hints and ideas are appriciated. My plan is to fit the data myself in Matlab as the available programs do not offer good fitting methods. I have compressed a JPK force map file in .zip, so I could attach it here. Hello,
I am trying to import force maps data from JPK and I could not find any clue on how to begin. Could anyone help me with how I could import raw data from force map files? Any hints and ideas are appriciated. My plan is to fit the data myself in Matlab as the available programs do not offer good fitting methods. I have compressed a JPK force map file in .zip, so I could attach it here. afm, jpk, force maps, import jpk force maps MATLAB Answers — New Questions
How can I identify and fill outliers in a 2d matrix?
Hello,
I am wondering if there is a function to identify and fill outliers in a 2d matrix. I know that the filloutliers function does work on a matrix, but it only works on each column separately. I am hoping to look at outliers in both directions.
There is a function fillmissing2 that does exactly this, but for missing values rather than outliers. Does anyone know if there is such a function? Or perhaps a workaround?
Thanks in advance,
SeanHello,
I am wondering if there is a function to identify and fill outliers in a 2d matrix. I know that the filloutliers function does work on a matrix, but it only works on each column separately. I am hoping to look at outliers in both directions.
There is a function fillmissing2 that does exactly this, but for missing values rather than outliers. Does anyone know if there is such a function? Or perhaps a workaround?
Thanks in advance,
Sean Hello,
I am wondering if there is a function to identify and fill outliers in a 2d matrix. I know that the filloutliers function does work on a matrix, but it only works on each column separately. I am hoping to look at outliers in both directions.
There is a function fillmissing2 that does exactly this, but for missing values rather than outliers. Does anyone know if there is such a function? Or perhaps a workaround?
Thanks in advance,
Sean filloutliers, matrix, interpolation MATLAB Answers — New Questions
Invalid Parameter Name: EdgeColor
Hi all,
I’m trying to set the edgecolor parameter to interp for a hist3 plot. But MATLAB keeps giving me an invalid parameter error on edgecolor. It is in the documentation as a valid parameter and as far as I can tell I’m using the latest version of MATLAB: R2024a Update 2. Another strange thing is that even though I get the error message in the Command Window. The figure that is generated does successfully change the edge colors. It seems like MATLAB is doing what I expected but giving an error message for no apparent reason.
I’ve included my implementation and error message for reference.
hist3(X,[250 250],"EdgeColor","interp","CdataMode","auto");
Error using internal.stats.parseArgs (line 43)
Invalid parameter name: EdgeColor.
Error in hist3 (line 278)
[cdatamode,facecolor,~] = internal.stats.parseArgs(plnames,pldflts,plotArgs{:});
Error in Heatmap_test (line 26)
hist3(X,[250 250],"EdgeColor","interp","CdataMode","auto");Hi all,
I’m trying to set the edgecolor parameter to interp for a hist3 plot. But MATLAB keeps giving me an invalid parameter error on edgecolor. It is in the documentation as a valid parameter and as far as I can tell I’m using the latest version of MATLAB: R2024a Update 2. Another strange thing is that even though I get the error message in the Command Window. The figure that is generated does successfully change the edge colors. It seems like MATLAB is doing what I expected but giving an error message for no apparent reason.
I’ve included my implementation and error message for reference.
hist3(X,[250 250],"EdgeColor","interp","CdataMode","auto");
Error using internal.stats.parseArgs (line 43)
Invalid parameter name: EdgeColor.
Error in hist3 (line 278)
[cdatamode,facecolor,~] = internal.stats.parseArgs(plnames,pldflts,plotArgs{:});
Error in Heatmap_test (line 26)
hist3(X,[250 250],"EdgeColor","interp","CdataMode","auto"); Hi all,
I’m trying to set the edgecolor parameter to interp for a hist3 plot. But MATLAB keeps giving me an invalid parameter error on edgecolor. It is in the documentation as a valid parameter and as far as I can tell I’m using the latest version of MATLAB: R2024a Update 2. Another strange thing is that even though I get the error message in the Command Window. The figure that is generated does successfully change the edge colors. It seems like MATLAB is doing what I expected but giving an error message for no apparent reason.
I’ve included my implementation and error message for reference.
hist3(X,[250 250],"EdgeColor","interp","CdataMode","auto");
Error using internal.stats.parseArgs (line 43)
Invalid parameter name: EdgeColor.
Error in hist3 (line 278)
[cdatamode,facecolor,~] = internal.stats.parseArgs(plnames,pldflts,plotArgs{:});
Error in Heatmap_test (line 26)
hist3(X,[250 250],"EdgeColor","interp","CdataMode","auto"); histogram, plotting, error MATLAB Answers — New Questions
solving linear system with decomposition(A,’qr’) and qr(A) produce different results
load post.mat
x1 = decomposition(CA,’qr’)b_f;
[qq2,rr2,pp2] = qr(CA);
x2= pp2 * (rr2(qq2’*b_f));
[qq3,rr3,pp3] = qr(CA,"econ","vector");
x3(pp3,:) = rr3(qq3’*b_f);
any(x1-x2~=0)
any(x3-x2~=0)
I know that the CA matrix is ill-conditioned. But that doesn’t explain the difference in solution, right?
Also, solving the system using decomposition(CA,’lu’) and lu(CA) produce the same results. So why not the ‘qr’ pair?load post.mat
x1 = decomposition(CA,’qr’)b_f;
[qq2,rr2,pp2] = qr(CA);
x2= pp2 * (rr2(qq2’*b_f));
[qq3,rr3,pp3] = qr(CA,"econ","vector");
x3(pp3,:) = rr3(qq3’*b_f);
any(x1-x2~=0)
any(x3-x2~=0)
I know that the CA matrix is ill-conditioned. But that doesn’t explain the difference in solution, right?
Also, solving the system using decomposition(CA,’lu’) and lu(CA) produce the same results. So why not the ‘qr’ pair? load post.mat
x1 = decomposition(CA,’qr’)b_f;
[qq2,rr2,pp2] = qr(CA);
x2= pp2 * (rr2(qq2’*b_f));
[qq3,rr3,pp3] = qr(CA,"econ","vector");
x3(pp3,:) = rr3(qq3’*b_f);
any(x1-x2~=0)
any(x3-x2~=0)
I know that the CA matrix is ill-conditioned. But that doesn’t explain the difference in solution, right?
Also, solving the system using decomposition(CA,’lu’) and lu(CA) produce the same results. So why not the ‘qr’ pair? qr decomposition, linear algebra, linear system MATLAB Answers — New Questions
Reset to original view for UIAxes control in AppDesigner programmatically
Hello,
I am trying to programmatically restore the zoom for original view for UIAxes compoinent in AppDesigner.
I’d like to achieve the same as clicking on the ‘house’ icon at the zoom controls.
Does anyone know how to do this?
–HanHello,
I am trying to programmatically restore the zoom for original view for UIAxes compoinent in AppDesigner.
I’d like to achieve the same as clicking on the ‘house’ icon at the zoom controls.
Does anyone know how to do this?
–Han Hello,
I am trying to programmatically restore the zoom for original view for UIAxes compoinent in AppDesigner.
I’d like to achieve the same as clicking on the ‘house’ icon at the zoom controls.
Does anyone know how to do this?
–Han appdesigner, uiaxes MATLAB Answers — New Questions
imagethreshold and ANN,INCREESING ACCURACY
if I have an ANN code to classify ADHA MRI images with little accuracy can I increese it if I make multithresholding for this MRI images , can I increes this accuracyif I have an ANN code to classify ADHA MRI images with little accuracy can I increese it if I make multithresholding for this MRI images , can I increes this accuracy if I have an ANN code to classify ADHA MRI images with little accuracy can I increese it if I make multithresholding for this MRI images , can I increes this accuracy image segmentation, ann, accuracy MATLAB Answers — New Questions
Optimization of a 10-DOF Vehicle model in Simulink
I have built a 10-DOF vehicle model for estimation of the lateral dynamics. Next task is to optimize it. For example, I want to find the optimal values of the Yaw moment of inertia (input) that maintain the Yaw Rate under a certain threshold for a given maneuver (Step steer).
The problem is that since the model is very complex, there is not a transfer function between these two.
Ideally, I want to use a genetic algorithm for these task.
Any suggestions on how to resolve this?I have built a 10-DOF vehicle model for estimation of the lateral dynamics. Next task is to optimize it. For example, I want to find the optimal values of the Yaw moment of inertia (input) that maintain the Yaw Rate under a certain threshold for a given maneuver (Step steer).
The problem is that since the model is very complex, there is not a transfer function between these two.
Ideally, I want to use a genetic algorithm for these task.
Any suggestions on how to resolve this? I have built a 10-DOF vehicle model for estimation of the lateral dynamics. Next task is to optimize it. For example, I want to find the optimal values of the Yaw moment of inertia (input) that maintain the Yaw Rate under a certain threshold for a given maneuver (Step steer).
The problem is that since the model is very complex, there is not a transfer function between these two.
Ideally, I want to use a genetic algorithm for these task.
Any suggestions on how to resolve this? simulink, vehicle dynamics, optimization, genetic algorithms MATLAB Answers — New Questions
GUI development.
Hello.
I am getting the following error for every GUI I try to execute. Can someone please explain what is wrong?
??? Attempt to reference field of non-structure array.
Error in ==> myAdder>add_pushbutton_Callback at 134
a = get(handles.input1_editText,’String’);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> myAdder at 42
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback
I executed the myadder GUI given here:
http://blinkdagger.com/matlab/matlab-gui-graphical-user-interface-tutorial-for-beginners/Hello.
I am getting the following error for every GUI I try to execute. Can someone please explain what is wrong?
??? Attempt to reference field of non-structure array.
Error in ==> myAdder>add_pushbutton_Callback at 134
a = get(handles.input1_editText,’String’);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> myAdder at 42
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback
I executed the myadder GUI given here:
http://blinkdagger.com/matlab/matlab-gui-graphical-user-interface-tutorial-for-beginners/ Hello.
I am getting the following error for every GUI I try to execute. Can someone please explain what is wrong?
??? Attempt to reference field of non-structure array.
Error in ==> myAdder>add_pushbutton_Callback at 134
a = get(handles.input1_editText,’String’);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> myAdder at 42
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback
I executed the myadder GUI given here:
http://blinkdagger.com/matlab/matlab-gui-graphical-user-interface-tutorial-for-beginners/ gui MATLAB Answers — New Questions
How do I write a projectile motion code that is automated and plots motion given certain heights, angles and initial velocity?
I need help writing a "for" or "while" code that is automated in a sense where it plots the projectile’s motion given the heights, angles and initial velocity. I am not including drag or rolling after the initial launch since I want to learn the basics.I need help writing a "for" or "while" code that is automated in a sense where it plots the projectile’s motion given the heights, angles and initial velocity. I am not including drag or rolling after the initial launch since I want to learn the basics. I need help writing a "for" or "while" code that is automated in a sense where it plots the projectile’s motion given the heights, angles and initial velocity. I am not including drag or rolling after the initial launch since I want to learn the basics. plot, plotting, for loop, while loop MATLAB Answers — New Questions
how can i rescale image? standard is at the center part
hello, i want to rescale image using the center standard, not at the corner of the imge
I attatched the example image, the red square is the reference image, and the blue one is the rescaled image (here, the center part is marked as ‘X’, and not only this enlarging case, i want to apply this algorithm for reduction case)
i want to use affine transform or any other method using interpolation, and i want to input the ratio of rescale and output of the rescaled image
I repreciate to all of your answers thanks a lot :))hello, i want to rescale image using the center standard, not at the corner of the imge
I attatched the example image, the red square is the reference image, and the blue one is the rescaled image (here, the center part is marked as ‘X’, and not only this enlarging case, i want to apply this algorithm for reduction case)
i want to use affine transform or any other method using interpolation, and i want to input the ratio of rescale and output of the rescaled image
I repreciate to all of your answers thanks a lot :)) hello, i want to rescale image using the center standard, not at the corner of the imge
I attatched the example image, the red square is the reference image, and the blue one is the rescaled image (here, the center part is marked as ‘X’, and not only this enlarging case, i want to apply this algorithm for reduction case)
i want to use affine transform or any other method using interpolation, and i want to input the ratio of rescale and output of the rescaled image
I repreciate to all of your answers thanks a lot :)) image rescale, affine transform, center part, imwarp MATLAB Answers — New Questions
imcrop not working for tiff
Hi, i want to crop several .tiff pics so i wrote below code but it dosnt work for .tiff files. it works for .png .jepg . i used imshow it shows nothing for .tiff files.
clc;
clear all;
address=’D:alluni things1-mastermaster project6-Data1-pics1-main2L2-E5′;
filenames=dir(fullfile(address,’*.tiff’));
for n=1:numel(filenames)
fullname=fullfile(address,filenames(n).name);
t1=imread(fullname);
info = imfinfo(fullname);
t2=imcrop(t1,[10, 10, 1000, 950]);
t3=size(t2);
imwrite(t2,fullname);
endHi, i want to crop several .tiff pics so i wrote below code but it dosnt work for .tiff files. it works for .png .jepg . i used imshow it shows nothing for .tiff files.
clc;
clear all;
address=’D:alluni things1-mastermaster project6-Data1-pics1-main2L2-E5′;
filenames=dir(fullfile(address,’*.tiff’));
for n=1:numel(filenames)
fullname=fullfile(address,filenames(n).name);
t1=imread(fullname);
info = imfinfo(fullname);
t2=imcrop(t1,[10, 10, 1000, 950]);
t3=size(t2);
imwrite(t2,fullname);
end Hi, i want to crop several .tiff pics so i wrote below code but it dosnt work for .tiff files. it works for .png .jepg . i used imshow it shows nothing for .tiff files.
clc;
clear all;
address=’D:alluni things1-mastermaster project6-Data1-pics1-main2L2-E5′;
filenames=dir(fullfile(address,’*.tiff’));
for n=1:numel(filenames)
fullname=fullfile(address,filenames(n).name);
t1=imread(fullname);
info = imfinfo(fullname);
t2=imcrop(t1,[10, 10, 1000, 950]);
t3=size(t2);
imwrite(t2,fullname);
end .tiff, image processing, imcrop MATLAB Answers — New Questions
¿Could you help me to activate MatLab?
I had a crash in my computer, I downloaded again the application, but I have no the activation Key
Thanks in advance and Best Regards
Jaime TamaritI had a crash in my computer, I downloaded again the application, but I have no the activation Key
Thanks in advance and Best Regards
Jaime Tamarit I had a crash in my computer, I downloaded again the application, but I have no the activation Key
Thanks in advance and Best Regards
Jaime Tamarit activation of matlab MATLAB Answers — New Questions
Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02.
I want to solve a system of equations containing two non-linear equations, one of which is Psh==Pse,the other is Qs==0, but solving it with the fsolve function doesn’t achieve the given constraints, how can I solve this problem?
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
rho=0:2*pi/24:2*pi;
V_se=0.2*V_r;
Z_r=j*X_r;
for m=1:25
fun=@(x)myfun(x,rho(m));
x0=[0 0];
[x,fval,exitflag(m),~]=fsolve(fun,x0);
gamma(m)=x(1);
I_sh(m)=x(2);
I_r(m)=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho(m))-V_r*exp(j*theta_r)-j*X_t*I_sh(m)*exp(j*gamma(m)));
V_c1(m)=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh(m)*exp(j*gamma(m))+I_r(m));
Psh(m)=real(V_c1(m)*conj(I_sh(m)*exp(j*gamma(m))));
Pse(m)=real(V_se*exp(j*rho(m))*conj(I_r(m)));
Pr(m)=real(V_r*exp(j*theta_r)*conj(I_r(m)));
Qr(m)=imag(V_r*exp(j*theta_r)*conj(I_r(m)));
Sr(m)=sqrt(Pr(m)^2+Qr(m)^2);
Ps(m)=real(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Qs(m)=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Ss(m)=sqrt(Ps(m)^2+Qs(m)^2);
end
plot( Ps/Srate,Qs/Srate,LineWidth=2,color='[0.9290 0.6940 0.1250]’)
function y=myfun(x,rho)
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
V_se=0.2*V_r;
Z_r=j*X_r;
%%%%%%%%%%%%%%%%Two constraints,Psh==Pse,Qs==0
gamma=x(1);
I_sh=x(2);
I_r=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho)-V_r*exp(j*theta_r)-j*X_t*I_sh*exp(j*gamma));
V_c1=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh*exp(j*gamma)+I_r);
Psh=real(V_c1*conj(I_sh*exp(j*gamma)));
Pse=real(V_se*exp(j*rho)*conj(I_r));
Qs=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r+I_sh*exp(j*gamma)));
y=[Psh-Pse; Qs];
endI want to solve a system of equations containing two non-linear equations, one of which is Psh==Pse,the other is Qs==0, but solving it with the fsolve function doesn’t achieve the given constraints, how can I solve this problem?
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
rho=0:2*pi/24:2*pi;
V_se=0.2*V_r;
Z_r=j*X_r;
for m=1:25
fun=@(x)myfun(x,rho(m));
x0=[0 0];
[x,fval,exitflag(m),~]=fsolve(fun,x0);
gamma(m)=x(1);
I_sh(m)=x(2);
I_r(m)=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho(m))-V_r*exp(j*theta_r)-j*X_t*I_sh(m)*exp(j*gamma(m)));
V_c1(m)=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh(m)*exp(j*gamma(m))+I_r(m));
Psh(m)=real(V_c1(m)*conj(I_sh(m)*exp(j*gamma(m))));
Pse(m)=real(V_se*exp(j*rho(m))*conj(I_r(m)));
Pr(m)=real(V_r*exp(j*theta_r)*conj(I_r(m)));
Qr(m)=imag(V_r*exp(j*theta_r)*conj(I_r(m)));
Sr(m)=sqrt(Pr(m)^2+Qr(m)^2);
Ps(m)=real(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Qs(m)=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Ss(m)=sqrt(Ps(m)^2+Qs(m)^2);
end
plot( Ps/Srate,Qs/Srate,LineWidth=2,color='[0.9290 0.6940 0.1250]’)
function y=myfun(x,rho)
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
V_se=0.2*V_r;
Z_r=j*X_r;
%%%%%%%%%%%%%%%%Two constraints,Psh==Pse,Qs==0
gamma=x(1);
I_sh=x(2);
I_r=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho)-V_r*exp(j*theta_r)-j*X_t*I_sh*exp(j*gamma));
V_c1=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh*exp(j*gamma)+I_r);
Psh=real(V_c1*conj(I_sh*exp(j*gamma)));
Pse=real(V_se*exp(j*rho)*conj(I_r));
Qs=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r+I_sh*exp(j*gamma)));
y=[Psh-Pse; Qs];
end I want to solve a system of equations containing two non-linear equations, one of which is Psh==Pse,the other is Qs==0, but solving it with the fsolve function doesn’t achieve the given constraints, how can I solve this problem?
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
rho=0:2*pi/24:2*pi;
V_se=0.2*V_r;
Z_r=j*X_r;
for m=1:25
fun=@(x)myfun(x,rho(m));
x0=[0 0];
[x,fval,exitflag(m),~]=fsolve(fun,x0);
gamma(m)=x(1);
I_sh(m)=x(2);
I_r(m)=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho(m))-V_r*exp(j*theta_r)-j*X_t*I_sh(m)*exp(j*gamma(m)));
V_c1(m)=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh(m)*exp(j*gamma(m))+I_r(m));
Psh(m)=real(V_c1(m)*conj(I_sh(m)*exp(j*gamma(m))));
Pse(m)=real(V_se*exp(j*rho(m))*conj(I_r(m)));
Pr(m)=real(V_r*exp(j*theta_r)*conj(I_r(m)));
Qr(m)=imag(V_r*exp(j*theta_r)*conj(I_r(m)));
Sr(m)=sqrt(Pr(m)^2+Qr(m)^2);
Ps(m)=real(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Qs(m)=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r(m)+I_sh(m)*exp(j*gamma(m))));
Ss(m)=sqrt(Ps(m)^2+Qs(m)^2);
end
plot( Ps/Srate,Qs/Srate,LineWidth=2,color='[0.9290 0.6940 0.1250]’)
function y=myfun(x,rho)
V_s=10*1e3/sqrt(3);
n_t=25*sqrt(3);
V_r=400/sqrt(3);
theta_r=pi/12;
Srate=100*1e3/3;
Zbase=(V_r)^2/Srate;
X_r=0.4*Zbase;
X_t=400^2/(150*1e3)*4/100;
V_se=0.2*V_r;
Z_r=j*X_r;
%%%%%%%%%%%%%%%%Two constraints,Psh==Pse,Qs==0
gamma=x(1);
I_sh=x(2);
I_r=1/(Z_r+j*X_t)*(sqrt(3)*V_s*exp(j*pi/6)/n_t+V_se*exp(j*rho)-V_r*exp(j*theta_r)-j*X_t*I_sh*exp(j*gamma));
V_c1=sqrt(3)*V_s*exp(j*pi/6)/n_t-j*X_t*(I_sh*exp(j*gamma)+I_r);
Psh=real(V_c1*conj(I_sh*exp(j*gamma)));
Pse=real(V_se*exp(j*rho)*conj(I_r));
Qs=imag(sqrt(3)*V_s*exp(j*pi/6)/n_t*conj(I_r+I_sh*exp(j*gamma)));
y=[Psh-Pse; Qs];
end fsolve, solving systems of nonlinear equations MATLAB Answers — New Questions
How to run two simulink models in parallel?
Hello everyone,
I am working with a 3DOF model of a commercial airplane in MatLab/Simulink. This model contains the state propagator and the autopilot. I would like to train an RL agent using the outputs of this model. The problem is that the environment for the RL application contains an exact copy of the state propagator of the 3DOF model. How can I use two of these systems without conflicting with the goto/from blocks and the signal name?
Thank youHello everyone,
I am working with a 3DOF model of a commercial airplane in MatLab/Simulink. This model contains the state propagator and the autopilot. I would like to train an RL agent using the outputs of this model. The problem is that the environment for the RL application contains an exact copy of the state propagator of the 3DOF model. How can I use two of these systems without conflicting with the goto/from blocks and the signal name?
Thank you Hello everyone,
I am working with a 3DOF model of a commercial airplane in MatLab/Simulink. This model contains the state propagator and the autopilot. I would like to train an RL agent using the outputs of this model. The problem is that the environment for the RL application contains an exact copy of the state propagator of the 3DOF model. How can I use two of these systems without conflicting with the goto/from blocks and the signal name?
Thank you simulink, subsystem, scope MATLAB Answers — New Questions