Tag Archives: matlab
Fzero not converging, giving previous answer back.
Im trying to solve the water level across a fixed lip spillway by using fzero, but I ran into the problem that the function gives an initial answer and doesn’t change between iterations in my for loop. By manually advancing throuhg the loops i can see that in the first one fzero already begins drifting and stops converging on an answer, giving me my last iterations (the first ever answer it got) back to me.
close all
clear all
clc
%% Que longitud de aliviadero necesito para aliviar hasta un calado determinado con la entrada de un caudal dado?
%%
%determino caudal de entrada
Poblacion=10000;
Dotacion=200; %l/hab*dia
coef_aguas_negras=0.8;%cuanto agua dotada pasa a aguias negras
coef_punta=2; %coeficiente de punta de aguas residuales pico comparada con caudal medio, 2 en poblaciones pequeñas (desfavorable)
Q_diario=Poblacion*Dotacion*coef_aguas_negras*1/1000%pasamos a m3/dia
Q_med=Q_diario/(24*3600) %dividimos el caudal a lo largo del dia y lo pasamos a m3/s
Q_punta=coef_punta*Q_med
Q_gris=10*Q_med%caudal a partir del cual se determina agua gris y está suficientemente diluido como para verter a cauce sin tratar (aliviadero vierte a partir de este caudal)
%%
%dimensiones de tubería a aliviar
%tomo tubería rectangular para este ejemplo
b=1
%para calcular c se necesita calcular la velocidad de flujo por el conducto
%(V=Q/A)
i=0.001 %pendiente del fondo del 1 por mil
n=0.015
%uso manning para conseguir c
ec1=@(y) 1/n*((b*y)/(b+2*y))^(2/3)*i^(1/2)*b*y-Q_gris;
y=fzero(ec1,1);
%redondeo hacia arriba (los 10 cm hacia arriba)
c=ceil(y*10)/10;
%%
%creo el espacio del vector de puntos diferenciales a lo largo del
%aliviadero
L=5;
dx=0.1;
x=[0:dx:L];
%%
%INPUT
%meto el nivel al principio del aliviadero (se saca igual con manning
%arriba si tenemos un caudal de entrada
Q=1;
ec2=@(y) 1/n*((b*y)/(b+2*y))^(2/3)*i^(1/2)*[b*y]-Q;
%%
h1=zeros(1,length(x)-1);
h2=zeros(1,length(x)-1);
v1=zeros(1,length(x)-1);
v2=zeros(1,length(x)-1);
y1=fzero(ec2,1);
h1(1)=y1;
v_e=Q/(b*h1(1));
v1(1)=v_e;
q1=Q;
Q1(1)=q1;
Cv=1.86; %para la formula de aliviadero de pared delgada
g=9.81;
ec3=@(y2) 10^16*([y1]+[((v_e)^2)/(2*g)]-[y2]-[(((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))^2)/(2*g)]-[sqrt(((((v_e+((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))))/2)*n*((b+2*y2)^(2/3)))/((b*y2)^(2/3)))*dx]);
a=fzero(ec3,10);
y2=a;
h2(1)=y2;
q2=(q1-Cv*dx*(((y1+y2)/2)-c)^(3/2));
Q2(1)=q2;
v2(1)=q2/(b*h2(1));
%%
for k=2:length(x)
y1=h2(k-1);
v_e=v2(k-1);
q1=Q2(k-1);
a=fzero(ec3,10);
y2=a;
h2(k)=y2;
q2=(q1-Cv*dx*(((y1+y2)/2)-c)^(3/2));
Q2(k)=q2;
v2(k)=q2/(b*h2(k));
h1(k)=y1;
v1(k)=v_e;
end
%%
%intento diagnosticar el error de convergencia de fzero
figure ;
fplot(ec3,[-2,2]);
hold on
plot(y2,0,’r*’);
yline(0);
hold off
k=2;
y1=h2(k-1);
v_e=v2(k-1);
q1=Q2(k-1);
[a,fval,exitflag,output]=fzero(ec3,10)
drift=[y1]+[((v_e)^2)/(2*g)]-[y2]-[(((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))^2)/(2*g)]-[sqrt(((((v_e+((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))))/2)*n*((b+2*y2)^(2/3)))/((b*y2)^(2/3)))*dx];
figure ;
fplot(ec3,[-2,2]);
hold on
plot(y2,0,’r*’);
yline(0);
hold offIm trying to solve the water level across a fixed lip spillway by using fzero, but I ran into the problem that the function gives an initial answer and doesn’t change between iterations in my for loop. By manually advancing throuhg the loops i can see that in the first one fzero already begins drifting and stops converging on an answer, giving me my last iterations (the first ever answer it got) back to me.
close all
clear all
clc
%% Que longitud de aliviadero necesito para aliviar hasta un calado determinado con la entrada de un caudal dado?
%%
%determino caudal de entrada
Poblacion=10000;
Dotacion=200; %l/hab*dia
coef_aguas_negras=0.8;%cuanto agua dotada pasa a aguias negras
coef_punta=2; %coeficiente de punta de aguas residuales pico comparada con caudal medio, 2 en poblaciones pequeñas (desfavorable)
Q_diario=Poblacion*Dotacion*coef_aguas_negras*1/1000%pasamos a m3/dia
Q_med=Q_diario/(24*3600) %dividimos el caudal a lo largo del dia y lo pasamos a m3/s
Q_punta=coef_punta*Q_med
Q_gris=10*Q_med%caudal a partir del cual se determina agua gris y está suficientemente diluido como para verter a cauce sin tratar (aliviadero vierte a partir de este caudal)
%%
%dimensiones de tubería a aliviar
%tomo tubería rectangular para este ejemplo
b=1
%para calcular c se necesita calcular la velocidad de flujo por el conducto
%(V=Q/A)
i=0.001 %pendiente del fondo del 1 por mil
n=0.015
%uso manning para conseguir c
ec1=@(y) 1/n*((b*y)/(b+2*y))^(2/3)*i^(1/2)*b*y-Q_gris;
y=fzero(ec1,1);
%redondeo hacia arriba (los 10 cm hacia arriba)
c=ceil(y*10)/10;
%%
%creo el espacio del vector de puntos diferenciales a lo largo del
%aliviadero
L=5;
dx=0.1;
x=[0:dx:L];
%%
%INPUT
%meto el nivel al principio del aliviadero (se saca igual con manning
%arriba si tenemos un caudal de entrada
Q=1;
ec2=@(y) 1/n*((b*y)/(b+2*y))^(2/3)*i^(1/2)*[b*y]-Q;
%%
h1=zeros(1,length(x)-1);
h2=zeros(1,length(x)-1);
v1=zeros(1,length(x)-1);
v2=zeros(1,length(x)-1);
y1=fzero(ec2,1);
h1(1)=y1;
v_e=Q/(b*h1(1));
v1(1)=v_e;
q1=Q;
Q1(1)=q1;
Cv=1.86; %para la formula de aliviadero de pared delgada
g=9.81;
ec3=@(y2) 10^16*([y1]+[((v_e)^2)/(2*g)]-[y2]-[(((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))^2)/(2*g)]-[sqrt(((((v_e+((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))))/2)*n*((b+2*y2)^(2/3)))/((b*y2)^(2/3)))*dx]);
a=fzero(ec3,10);
y2=a;
h2(1)=y2;
q2=(q1-Cv*dx*(((y1+y2)/2)-c)^(3/2));
Q2(1)=q2;
v2(1)=q2/(b*h2(1));
%%
for k=2:length(x)
y1=h2(k-1);
v_e=v2(k-1);
q1=Q2(k-1);
a=fzero(ec3,10);
y2=a;
h2(k)=y2;
q2=(q1-Cv*dx*(((y1+y2)/2)-c)^(3/2));
Q2(k)=q2;
v2(k)=q2/(b*h2(k));
h1(k)=y1;
v1(k)=v_e;
end
%%
%intento diagnosticar el error de convergencia de fzero
figure ;
fplot(ec3,[-2,2]);
hold on
plot(y2,0,’r*’);
yline(0);
hold off
k=2;
y1=h2(k-1);
v_e=v2(k-1);
q1=Q2(k-1);
[a,fval,exitflag,output]=fzero(ec3,10)
drift=[y1]+[((v_e)^2)/(2*g)]-[y2]-[(((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))^2)/(2*g)]-[sqrt(((((v_e+((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))))/2)*n*((b+2*y2)^(2/3)))/((b*y2)^(2/3)))*dx];
figure ;
fplot(ec3,[-2,2]);
hold on
plot(y2,0,’r*’);
yline(0);
hold off Im trying to solve the water level across a fixed lip spillway by using fzero, but I ran into the problem that the function gives an initial answer and doesn’t change between iterations in my for loop. By manually advancing throuhg the loops i can see that in the first one fzero already begins drifting and stops converging on an answer, giving me my last iterations (the first ever answer it got) back to me.
close all
clear all
clc
%% Que longitud de aliviadero necesito para aliviar hasta un calado determinado con la entrada de un caudal dado?
%%
%determino caudal de entrada
Poblacion=10000;
Dotacion=200; %l/hab*dia
coef_aguas_negras=0.8;%cuanto agua dotada pasa a aguias negras
coef_punta=2; %coeficiente de punta de aguas residuales pico comparada con caudal medio, 2 en poblaciones pequeñas (desfavorable)
Q_diario=Poblacion*Dotacion*coef_aguas_negras*1/1000%pasamos a m3/dia
Q_med=Q_diario/(24*3600) %dividimos el caudal a lo largo del dia y lo pasamos a m3/s
Q_punta=coef_punta*Q_med
Q_gris=10*Q_med%caudal a partir del cual se determina agua gris y está suficientemente diluido como para verter a cauce sin tratar (aliviadero vierte a partir de este caudal)
%%
%dimensiones de tubería a aliviar
%tomo tubería rectangular para este ejemplo
b=1
%para calcular c se necesita calcular la velocidad de flujo por el conducto
%(V=Q/A)
i=0.001 %pendiente del fondo del 1 por mil
n=0.015
%uso manning para conseguir c
ec1=@(y) 1/n*((b*y)/(b+2*y))^(2/3)*i^(1/2)*b*y-Q_gris;
y=fzero(ec1,1);
%redondeo hacia arriba (los 10 cm hacia arriba)
c=ceil(y*10)/10;
%%
%creo el espacio del vector de puntos diferenciales a lo largo del
%aliviadero
L=5;
dx=0.1;
x=[0:dx:L];
%%
%INPUT
%meto el nivel al principio del aliviadero (se saca igual con manning
%arriba si tenemos un caudal de entrada
Q=1;
ec2=@(y) 1/n*((b*y)/(b+2*y))^(2/3)*i^(1/2)*[b*y]-Q;
%%
h1=zeros(1,length(x)-1);
h2=zeros(1,length(x)-1);
v1=zeros(1,length(x)-1);
v2=zeros(1,length(x)-1);
y1=fzero(ec2,1);
h1(1)=y1;
v_e=Q/(b*h1(1));
v1(1)=v_e;
q1=Q;
Q1(1)=q1;
Cv=1.86; %para la formula de aliviadero de pared delgada
g=9.81;
ec3=@(y2) 10^16*([y1]+[((v_e)^2)/(2*g)]-[y2]-[(((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))^2)/(2*g)]-[sqrt(((((v_e+((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))))/2)*n*((b+2*y2)^(2/3)))/((b*y2)^(2/3)))*dx]);
a=fzero(ec3,10);
y2=a;
h2(1)=y2;
q2=(q1-Cv*dx*(((y1+y2)/2)-c)^(3/2));
Q2(1)=q2;
v2(1)=q2/(b*h2(1));
%%
for k=2:length(x)
y1=h2(k-1);
v_e=v2(k-1);
q1=Q2(k-1);
a=fzero(ec3,10);
y2=a;
h2(k)=y2;
q2=(q1-Cv*dx*(((y1+y2)/2)-c)^(3/2));
Q2(k)=q2;
v2(k)=q2/(b*h2(k));
h1(k)=y1;
v1(k)=v_e;
end
%%
%intento diagnosticar el error de convergencia de fzero
figure ;
fplot(ec3,[-2,2]);
hold on
plot(y2,0,’r*’);
yline(0);
hold off
k=2;
y1=h2(k-1);
v_e=v2(k-1);
q1=Q2(k-1);
[a,fval,exitflag,output]=fzero(ec3,10)
drift=[y1]+[((v_e)^2)/(2*g)]-[y2]-[(((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))^2)/(2*g)]-[sqrt(((((v_e+((q1-Cv*dx*(((y1+y2)/2)-c)^(3/2))/(b*y2))))/2)*n*((b+2*y2)^(2/3)))/((b*y2)^(2/3)))*dx];
figure ;
fplot(ec3,[-2,2]);
hold on
plot(y2,0,’r*’);
yline(0);
hold off fzero, convergence, exitflag=1 MATLAB Answers — New Questions
I am interafacing 8051 via serial port.How can i achieve this?
Can I use Simulink for sending the data to the 8051 via rs232?Can I use Simulink for sending the data to the 8051 via rs232? Can I use Simulink for sending the data to the 8051 via rs232? rs232, interface, serial port, microcontroller, amtel, at8051 MATLAB Answers — New Questions
How to interface Matlab/Simulink RS2328051 Micrcontroller?
How to interface Matlab/Simulink <—>RS232<—>8051 Micrcontroller?
Say for example by sending a bit signal from Matlab through RS232 to 8051, a LED should glow.
Is this possible?How to interface Matlab/Simulink <—>RS232<—>8051 Micrcontroller?
Say for example by sending a bit signal from Matlab through RS232 to 8051, a LED should glow.
Is this possible? How to interface Matlab/Simulink <—>RS232<—>8051 Micrcontroller?
Say for example by sending a bit signal from Matlab through RS232 to 8051, a LED should glow.
Is this possible? image processing, embedded matlab function, serial, programming MATLAB Answers — New Questions
How to check Serial port continuously
My task is to capture image only when char ‘A’ is received through COM port. So How to contineously monitor COM port to check whether data is received or no on COM port.My task is to capture image only when char ‘A’ is received through COM port. So How to contineously monitor COM port to check whether data is received or no on COM port. My task is to capture image only when char ‘A’ is received through COM port. So How to contineously monitor COM port to check whether data is received or no on COM port. scanning com port MATLAB Answers — New Questions
EEGLAB “pop_eeg_spektrine_galia”
When saving in the eeglab darbeliai "pop_eeg_spektrine_galia" section, there is absolute power and relational power. I am curious about the difference between them, and whether fft is applied and saved.When saving in the eeglab darbeliai "pop_eeg_spektrine_galia" section, there is absolute power and relational power. I am curious about the difference between them, and whether fft is applied and saved. When saving in the eeglab darbeliai "pop_eeg_spektrine_galia" section, there is absolute power and relational power. I am curious about the difference between them, and whether fft is applied and saved. eeglab, fft MATLAB Answers — New Questions
Analyzing Sections of Table Based on One Variable
Hello,
I have a large table (we’ll say something like 8 x 100, but it will more likely having over 10,000 rows).
The last column represents "time in a day", and the 100 rows represents several days worth of data.
Everytime the day hits midnight, the last column has a value of 0.
It’s worth noting that the last column isn’t quite a single 24-hr time frame, so the last column doesn’t always increase throughout the day before it drops back to time 0.
However, there are not an equal amount of rows for each day.
So far example, Day 1 might have 18 rows, Day 2 will have 35 rows, Day 3 will have 40 rows, and Day 4 will have 7 rows.
Each Day will always begin with a value of 0 for the last column.
The total number of days and how many rows per day are both never constant (i.e. it will vary).
I don’t necessarily want to split the larger table into 4 smaller tables (after reading other forum posts it seems this can lead to many bugs and errors), although this might accomplish what I’m looking for.
Rather, I want to be able to (A) compare the first row of Day 1 and with first row of Day 2, and compare Day 1 with Day 3, etc.
Then (B) determine if the first rows of Days 1 and 2 are similar enough to not worry about Day 2’s data.
I have a script already that accomplished step B (previously I was arbitralilty splitting the larger table).
But since know I want each section from the larger table to have a unique number of rows, I’m having difficulty accomplishing this.
In pseudocode, I was starting to do something like:
for i=1:N
if LastCol(i)==0
% Save all data between point i and point right before LastCol(i)==0 again
end
end
One thing that I can have known prior to this is how many days will be in the large table.
So for example, in the above example, I will know that there are 4 days, which corresponds to 4 zeros in the last column.
If my request seems confusing or convoluted, please let me know and I can explain further or take it down.
In Short: My main issue is how I split the table up in unique sizes.
Thanks.
Edit:
I thought of a couple of for loops that sort of help my issue.
I have two matrices: One with four datapoints corresponding the running time of the first day. And one that is the whole table.
for i=1:Length_Table
for j=1:Num_Days
if Big_Table.A(i)==Day_Matrix(j)
% Not Sure
else
end
end
end
where Big_Table.A column corresponds to the overall running time (doesn’t reset after each day).
If at any time for the Big Table of Data equals a time when we know the day resets, then that’s where I want to begin a "new section" and end that section at the point before the it happens again.
I’m not sure how to do this task, however.Hello,
I have a large table (we’ll say something like 8 x 100, but it will more likely having over 10,000 rows).
The last column represents "time in a day", and the 100 rows represents several days worth of data.
Everytime the day hits midnight, the last column has a value of 0.
It’s worth noting that the last column isn’t quite a single 24-hr time frame, so the last column doesn’t always increase throughout the day before it drops back to time 0.
However, there are not an equal amount of rows for each day.
So far example, Day 1 might have 18 rows, Day 2 will have 35 rows, Day 3 will have 40 rows, and Day 4 will have 7 rows.
Each Day will always begin with a value of 0 for the last column.
The total number of days and how many rows per day are both never constant (i.e. it will vary).
I don’t necessarily want to split the larger table into 4 smaller tables (after reading other forum posts it seems this can lead to many bugs and errors), although this might accomplish what I’m looking for.
Rather, I want to be able to (A) compare the first row of Day 1 and with first row of Day 2, and compare Day 1 with Day 3, etc.
Then (B) determine if the first rows of Days 1 and 2 are similar enough to not worry about Day 2’s data.
I have a script already that accomplished step B (previously I was arbitralilty splitting the larger table).
But since know I want each section from the larger table to have a unique number of rows, I’m having difficulty accomplishing this.
In pseudocode, I was starting to do something like:
for i=1:N
if LastCol(i)==0
% Save all data between point i and point right before LastCol(i)==0 again
end
end
One thing that I can have known prior to this is how many days will be in the large table.
So for example, in the above example, I will know that there are 4 days, which corresponds to 4 zeros in the last column.
If my request seems confusing or convoluted, please let me know and I can explain further or take it down.
In Short: My main issue is how I split the table up in unique sizes.
Thanks.
Edit:
I thought of a couple of for loops that sort of help my issue.
I have two matrices: One with four datapoints corresponding the running time of the first day. And one that is the whole table.
for i=1:Length_Table
for j=1:Num_Days
if Big_Table.A(i)==Day_Matrix(j)
% Not Sure
else
end
end
end
where Big_Table.A column corresponds to the overall running time (doesn’t reset after each day).
If at any time for the Big Table of Data equals a time when we know the day resets, then that’s where I want to begin a "new section" and end that section at the point before the it happens again.
I’m not sure how to do this task, however. Hello,
I have a large table (we’ll say something like 8 x 100, but it will more likely having over 10,000 rows).
The last column represents "time in a day", and the 100 rows represents several days worth of data.
Everytime the day hits midnight, the last column has a value of 0.
It’s worth noting that the last column isn’t quite a single 24-hr time frame, so the last column doesn’t always increase throughout the day before it drops back to time 0.
However, there are not an equal amount of rows for each day.
So far example, Day 1 might have 18 rows, Day 2 will have 35 rows, Day 3 will have 40 rows, and Day 4 will have 7 rows.
Each Day will always begin with a value of 0 for the last column.
The total number of days and how many rows per day are both never constant (i.e. it will vary).
I don’t necessarily want to split the larger table into 4 smaller tables (after reading other forum posts it seems this can lead to many bugs and errors), although this might accomplish what I’m looking for.
Rather, I want to be able to (A) compare the first row of Day 1 and with first row of Day 2, and compare Day 1 with Day 3, etc.
Then (B) determine if the first rows of Days 1 and 2 are similar enough to not worry about Day 2’s data.
I have a script already that accomplished step B (previously I was arbitralilty splitting the larger table).
But since know I want each section from the larger table to have a unique number of rows, I’m having difficulty accomplishing this.
In pseudocode, I was starting to do something like:
for i=1:N
if LastCol(i)==0
% Save all data between point i and point right before LastCol(i)==0 again
end
end
One thing that I can have known prior to this is how many days will be in the large table.
So for example, in the above example, I will know that there are 4 days, which corresponds to 4 zeros in the last column.
If my request seems confusing or convoluted, please let me know and I can explain further or take it down.
In Short: My main issue is how I split the table up in unique sizes.
Thanks.
Edit:
I thought of a couple of for loops that sort of help my issue.
I have two matrices: One with four datapoints corresponding the running time of the first day. And one that is the whole table.
for i=1:Length_Table
for j=1:Num_Days
if Big_Table.A(i)==Day_Matrix(j)
% Not Sure
else
end
end
end
where Big_Table.A column corresponds to the overall running time (doesn’t reset after each day).
If at any time for the Big Table of Data equals a time when we know the day resets, then that’s where I want to begin a "new section" and end that section at the point before the it happens again.
I’m not sure how to do this task, however. matlab, if statement, table, search MATLAB Answers — New Questions
Kalman Filter – Activating or Enabling a matlab function block in simulink
Hello,
I have data of 3 signals in matlab workspace and each signal was recorded with different sampling rate. I want to use these signals in simulink however i am not sure what is the best way to do that for my case.
I have build a kalman filter in simulink that was tested using simulated data. Now I have real data which means the setup is slightly different. I want to trigger a matlab function block to be used only when data is available.
Any ideas how to do that?
Thank you.Hello,
I have data of 3 signals in matlab workspace and each signal was recorded with different sampling rate. I want to use these signals in simulink however i am not sure what is the best way to do that for my case.
I have build a kalman filter in simulink that was tested using simulated data. Now I have real data which means the setup is slightly different. I want to trigger a matlab function block to be used only when data is available.
Any ideas how to do that?
Thank you. Hello,
I have data of 3 signals in matlab workspace and each signal was recorded with different sampling rate. I want to use these signals in simulink however i am not sure what is the best way to do that for my case.
I have build a kalman filter in simulink that was tested using simulated data. Now I have real data which means the setup is slightly different. I want to trigger a matlab function block to be used only when data is available.
Any ideas how to do that?
Thank you. simulink, data import, parameter estimation, recursive estimation MATLAB Answers — New Questions
gfit error message in generalized Pareto (GP) distribution
Hello,
I compute return period using gpfit (Generalized Pareto parameter estimates) to calculate the return period, while I calculate the maximum likehood, I got an error message below.
Warning: Maximum likelihood has converged to an estimate of K < -1/2.
Confidence intervals and standard errors can not be computed reliably.> In gpfit (line 124)
I guess this happens with small values in the inputs, but I have no idea how to sort it out. Could you please help????
ThanksHello,
I compute return period using gpfit (Generalized Pareto parameter estimates) to calculate the return period, while I calculate the maximum likehood, I got an error message below.
Warning: Maximum likelihood has converged to an estimate of K < -1/2.
Confidence intervals and standard errors can not be computed reliably.> In gpfit (line 124)
I guess this happens with small values in the inputs, but I have no idea how to sort it out. Could you please help????
Thanks Hello,
I compute return period using gpfit (Generalized Pareto parameter estimates) to calculate the return period, while I calculate the maximum likehood, I got an error message below.
Warning: Maximum likelihood has converged to an estimate of K < -1/2.
Confidence intervals and standard errors can not be computed reliably.> In gpfit (line 124)
I guess this happens with small values in the inputs, but I have no idea how to sort it out. Could you please help????
Thanks pareto, statistics, (gp) distribution, extreme, gpfit, likelihood, gpd, error MATLAB Answers — New Questions
Sending Multiple Data to Excel from MATLAB?
Hi everybody,
I was wondering if it is possible to send multiple data from MATLAB to Excel in the same file?
At the moment I am using:
filename = ‘test.xlsx’
xlswrite(filename,MomentsX,1,’C1:F5′)
This only transfers the matrix ‘MomentsX’ into Excel. What If I want to send multiple data to the same spreadsheet in Excel?
Is this possible?
Many thanks in advance,
ScottHi everybody,
I was wondering if it is possible to send multiple data from MATLAB to Excel in the same file?
At the moment I am using:
filename = ‘test.xlsx’
xlswrite(filename,MomentsX,1,’C1:F5′)
This only transfers the matrix ‘MomentsX’ into Excel. What If I want to send multiple data to the same spreadsheet in Excel?
Is this possible?
Many thanks in advance,
Scott Hi everybody,
I was wondering if it is possible to send multiple data from MATLAB to Excel in the same file?
At the moment I am using:
filename = ‘test.xlsx’
xlswrite(filename,MomentsX,1,’C1:F5′)
This only transfers the matrix ‘MomentsX’ into Excel. What If I want to send multiple data to the same spreadsheet in Excel?
Is this possible?
Many thanks in advance,
Scott matlab to excel, data MATLAB Answers — New Questions
Why aren’t my Simulink functions being called properly when using nested Simulink functions, Stateflow charts, and Data Store blocks?
I used three subsystems: one subsystem contains a Stateflow chart, which includes the state. The other two subsystems contain Simulink functions, each with its own Stateflow block. I am using nested Simulink functions, and I am calling them through Stateflow. Additionally, I used Data Store blocks, but the Simulink functions are not being called properly. why? what is the reason anyone help me on that ?I used three subsystems: one subsystem contains a Stateflow chart, which includes the state. The other two subsystems contain Simulink functions, each with its own Stateflow block. I am using nested Simulink functions, and I am calling them through Stateflow. Additionally, I used Data Store blocks, but the Simulink functions are not being called properly. why? what is the reason anyone help me on that ? I used three subsystems: one subsystem contains a Stateflow chart, which includes the state. The other two subsystems contain Simulink functions, each with its own Stateflow block. I am using nested Simulink functions, and I am calling them through Stateflow. Additionally, I used Data Store blocks, but the Simulink functions are not being called properly. why? what is the reason anyone help me on that ? stateflow, simulink, functions, matlab MATLAB Answers — New Questions
Simulink Model does not run simulation – initializing never stops
Good evening,
I integrated a KULI FMU into a blank worksheet in SIMULINK, and connected an imput constant and a scope to check if the import function works.
It is compiling, starts initializing, but never finishes the initializion, and never runs the model. Any Idea how to solve that problem?
Solver configuration is set to auto.Good evening,
I integrated a KULI FMU into a blank worksheet in SIMULINK, and connected an imput constant and a scope to check if the import function works.
It is compiling, starts initializing, but never finishes the initializion, and never runs the model. Any Idea how to solve that problem?
Solver configuration is set to auto. Good evening,
I integrated a KULI FMU into a blank worksheet in SIMULINK, and connected an imput constant and a scope to check if the import function works.
It is compiling, starts initializing, but never finishes the initializion, and never runs the model. Any Idea how to solve that problem?
Solver configuration is set to auto. simulation, initalisation MATLAB Answers — New Questions
Looking for approach to import XLS data for code generation
I have XLS which contains signal names used in simulink model. With details of initial value, data type, minimum maximum value etc.
I want to "import" this xls data and load into Model Explorer . After compilation it should be possible to generate code as per signal details in xls file. Model will have the signal names present in xls file always.
Probably this is very known thing to simplify code generation. But i am not able to figure out how to do this ?
Any existing threads or solution with use of latest matlab features (below 2022b , 2017b prefered ) will be also a great help.I have XLS which contains signal names used in simulink model. With details of initial value, data type, minimum maximum value etc.
I want to "import" this xls data and load into Model Explorer . After compilation it should be possible to generate code as per signal details in xls file. Model will have the signal names present in xls file always.
Probably this is very known thing to simplify code generation. But i am not able to figure out how to do this ?
Any existing threads or solution with use of latest matlab features (below 2022b , 2017b prefered ) will be also a great help. I have XLS which contains signal names used in simulink model. With details of initial value, data type, minimum maximum value etc.
I want to "import" this xls data and load into Model Explorer . After compilation it should be possible to generate code as per signal details in xls file. Model will have the signal names present in xls file always.
Probably this is very known thing to simplify code generation. But i am not able to figure out how to do this ?
Any existing threads or solution with use of latest matlab features (below 2022b , 2017b prefered ) will be also a great help. importing excel data, embedded coder, data dictionary MATLAB Answers — New Questions
What happens if the termination condition is satisfied before the constraint in matlab’s fmincon?
I’m doing optimization using fmincon.
I used ObjectiveLimit to terminate the optimization when the size of the objective function is less than 0.2,
As I was writing the code, it seems that if the nonlinear constraints are satisfied, the termination condition is also satisfied.
However, when I run the code, the optimization is performed several times and then the code terminates.
I don’t understand this part.
Doesn’t fmincon perform optimization for cases that satisfy the constraints?
What happens if the termination condition is satisfied before the constraint in matlab’s fmincon?
Below is the output when optimization is finished.
fmincon stopped because the objective function value 6.018404e-04 is less than options.ObjectiveLimit = 2.000000e-01 and the relative maximum constraint violation 2.039171e-13 is less than options.ConstraintTolerance = 1.000000e-06
Thank you.I’m doing optimization using fmincon.
I used ObjectiveLimit to terminate the optimization when the size of the objective function is less than 0.2,
As I was writing the code, it seems that if the nonlinear constraints are satisfied, the termination condition is also satisfied.
However, when I run the code, the optimization is performed several times and then the code terminates.
I don’t understand this part.
Doesn’t fmincon perform optimization for cases that satisfy the constraints?
What happens if the termination condition is satisfied before the constraint in matlab’s fmincon?
Below is the output when optimization is finished.
fmincon stopped because the objective function value 6.018404e-04 is less than options.ObjectiveLimit = 2.000000e-01 and the relative maximum constraint violation 2.039171e-13 is less than options.ConstraintTolerance = 1.000000e-06
Thank you. I’m doing optimization using fmincon.
I used ObjectiveLimit to terminate the optimization when the size of the objective function is less than 0.2,
As I was writing the code, it seems that if the nonlinear constraints are satisfied, the termination condition is also satisfied.
However, when I run the code, the optimization is performed several times and then the code terminates.
I don’t understand this part.
Doesn’t fmincon perform optimization for cases that satisfy the constraints?
What happens if the termination condition is satisfied before the constraint in matlab’s fmincon?
Below is the output when optimization is finished.
fmincon stopped because the objective function value 6.018404e-04 is less than options.ObjectiveLimit = 2.000000e-01 and the relative maximum constraint violation 2.039171e-13 is less than options.ConstraintTolerance = 1.000000e-06
Thank you. matlab, code, fmincon, optimization, constraint MATLAB Answers — New Questions
Increase the size of MATLAB logo inside Simulink block
I want to increase the Matlab logo size inside the RL agent block and the size of 1/z inside the unit delay block but increasing the FOnt size is not working for them? what should I do?I want to increase the Matlab logo size inside the RL agent block and the size of 1/z inside the unit delay block but increasing the FOnt size is not working for them? what should I do? I want to increase the Matlab logo size inside the RL agent block and the size of 1/z inside the unit delay block but increasing the FOnt size is not working for them? what should I do? size increase, simulink blocks MATLAB Answers — New Questions
Memory usage of decomposition
Hello,
Consider linear systems Ax=b_i with A sparse and positive definite and several right hand sides b_i. In the experiments I have done, it is faster to use
dA = decomposition(A,’chol’,’upper’);
x_i = dAb_i; % repeat as needed
than the classical
R = chol(A);
x_i=R(R’b_i); % repeat as needed
But dA occupies much more memory than R
n = 1e5;d = 1e-5;rc = 1e-5;
A=sprand(n,n,d,rc);
A = A+A’+10*speye(n,n);
R = chol(A);
dA = decomposition(A,’chol’,’upper’);
memR = whos("R"); memR = memR.bytes;
memdA = whos("dA"); memdA = memdA.bytes;
fprintf(‘ R occupies %.1e bytes.ndA occupies %.1e bytesn’,memR,memdA)
Any idea of why? Any solution?
Thanks,
MarianoHello,
Consider linear systems Ax=b_i with A sparse and positive definite and several right hand sides b_i. In the experiments I have done, it is faster to use
dA = decomposition(A,’chol’,’upper’);
x_i = dAb_i; % repeat as needed
than the classical
R = chol(A);
x_i=R(R’b_i); % repeat as needed
But dA occupies much more memory than R
n = 1e5;d = 1e-5;rc = 1e-5;
A=sprand(n,n,d,rc);
A = A+A’+10*speye(n,n);
R = chol(A);
dA = decomposition(A,’chol’,’upper’);
memR = whos("R"); memR = memR.bytes;
memdA = whos("dA"); memdA = memdA.bytes;
fprintf(‘ R occupies %.1e bytes.ndA occupies %.1e bytesn’,memR,memdA)
Any idea of why? Any solution?
Thanks,
Mariano Hello,
Consider linear systems Ax=b_i with A sparse and positive definite and several right hand sides b_i. In the experiments I have done, it is faster to use
dA = decomposition(A,’chol’,’upper’);
x_i = dAb_i; % repeat as needed
than the classical
R = chol(A);
x_i=R(R’b_i); % repeat as needed
But dA occupies much more memory than R
n = 1e5;d = 1e-5;rc = 1e-5;
A=sprand(n,n,d,rc);
A = A+A’+10*speye(n,n);
R = chol(A);
dA = decomposition(A,’chol’,’upper’);
memR = whos("R"); memR = memR.bytes;
memdA = whos("dA"); memdA = memdA.bytes;
fprintf(‘ R occupies %.1e bytes.ndA occupies %.1e bytesn’,memR,memdA)
Any idea of why? Any solution?
Thanks,
Mariano linear systems, sparse matrix, decomposition, memory MATLAB Answers — New Questions
LaTeX interpreter with multiple strings or character vectors
I have a series of values in units of that I want to label on the x-axis using xticklabels(mylabels). I want to typeset the units using LaTeX command. Thus I specified latex as the interpretor for my tick labels using the commands:
ax=gca;
ax.TickLabelInterpreter=’Latex’;
The labels are displayed correctly when I set mylabels as cell array of character vectors as follows:
mylabels={‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,’$frac{3pi}{2}$’,’$2pi$’};
However, when I specify mylabels as a cell array of strings, or a string array, or a character array as follows, the labels are not displayed on the x-axis.
mylabels=[‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,… ‘$frac{3pi}{2}$’,’$2pi$’];
mylabels={"-2pi","-frac{3pi}{2}","-pi","-frac{pi}{2}","0~~~~", "frac{pi}{2}","pi","frac{3pi}{2}","2pi"};
mylabels=["-2pi","-frac{3pi}{2}","-pi","-frac{pi}{2}","0~~~~","frac{pi}{2}","pi","frac{3pi}{2}","2pi"];
I would like to understand what’s the problem here.
A complete MWE is given as follows:
figure;
xlabel("x")
ylabel("y")
xlim([-2*pi 2*pi])
xticks(-2*pi:pi/2:2*pi)
mylabels={‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,’$frac{3pi}{2}$’,’$2pi$’};
xticklabels(mylabels)
ax=gca;
ax.TickLabelInterpreter=’Latex’;
Thank you very much in advance!I have a series of values in units of that I want to label on the x-axis using xticklabels(mylabels). I want to typeset the units using LaTeX command. Thus I specified latex as the interpretor for my tick labels using the commands:
ax=gca;
ax.TickLabelInterpreter=’Latex’;
The labels are displayed correctly when I set mylabels as cell array of character vectors as follows:
mylabels={‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,’$frac{3pi}{2}$’,’$2pi$’};
However, when I specify mylabels as a cell array of strings, or a string array, or a character array as follows, the labels are not displayed on the x-axis.
mylabels=[‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,… ‘$frac{3pi}{2}$’,’$2pi$’];
mylabels={"-2pi","-frac{3pi}{2}","-pi","-frac{pi}{2}","0~~~~", "frac{pi}{2}","pi","frac{3pi}{2}","2pi"};
mylabels=["-2pi","-frac{3pi}{2}","-pi","-frac{pi}{2}","0~~~~","frac{pi}{2}","pi","frac{3pi}{2}","2pi"];
I would like to understand what’s the problem here.
A complete MWE is given as follows:
figure;
xlabel("x")
ylabel("y")
xlim([-2*pi 2*pi])
xticks(-2*pi:pi/2:2*pi)
mylabels={‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,’$frac{3pi}{2}$’,’$2pi$’};
xticklabels(mylabels)
ax=gca;
ax.TickLabelInterpreter=’Latex’;
Thank you very much in advance! I have a series of values in units of that I want to label on the x-axis using xticklabels(mylabels). I want to typeset the units using LaTeX command. Thus I specified latex as the interpretor for my tick labels using the commands:
ax=gca;
ax.TickLabelInterpreter=’Latex’;
The labels are displayed correctly when I set mylabels as cell array of character vectors as follows:
mylabels={‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,’$frac{3pi}{2}$’,’$2pi$’};
However, when I specify mylabels as a cell array of strings, or a string array, or a character array as follows, the labels are not displayed on the x-axis.
mylabels=[‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,… ‘$frac{3pi}{2}$’,’$2pi$’];
mylabels={"-2pi","-frac{3pi}{2}","-pi","-frac{pi}{2}","0~~~~", "frac{pi}{2}","pi","frac{3pi}{2}","2pi"};
mylabels=["-2pi","-frac{3pi}{2}","-pi","-frac{pi}{2}","0~~~~","frac{pi}{2}","pi","frac{3pi}{2}","2pi"];
I would like to understand what’s the problem here.
A complete MWE is given as follows:
figure;
xlabel("x")
ylabel("y")
xlim([-2*pi 2*pi])
xticks(-2*pi:pi/2:2*pi)
mylabels={‘$-2pi$’,’$-frac{3pi}{2}$’,’$-pi$’,’$-frac{pi}{2}$’,’0~~~~’,’$frac{pi}{2}$’,’$pi$’,’$frac{3pi}{2}$’,’$2pi$’};
xticklabels(mylabels)
ax=gca;
ax.TickLabelInterpreter=’Latex’;
Thank you very much in advance! plot, latex interpreter MATLAB Answers — New Questions
Needs solution for this Task from Matlab fundamentals course
Matlab fundamentals course:
7.Conditional Data Selection -> Logical Indexing(5/5) -> Visualizing Cricket StatisticsMatlab fundamentals course:
7.Conditional Data Selection -> Logical Indexing(5/5) -> Visualizing Cricket Statistics Matlab fundamentals course:
7.Conditional Data Selection -> Logical Indexing(5/5) -> Visualizing Cricket Statistics plot, text MATLAB Answers — New Questions
Time-Domain Responses of Multiple simulation with different model’s paramters
I need to compare the responses of various model’s parametrs , I’m using the multiple simulations panel in the simulink editor to run multiple simulations with varying values. I’m viewing the results in simulation manager, so I need to see as well the time-domain responses per multiple parameters, Is it possible to see/plot it in simulation manager?
Since I’m using "on-line" matlab version I can open Data InspectorI need to compare the responses of various model’s parametrs , I’m using the multiple simulations panel in the simulink editor to run multiple simulations with varying values. I’m viewing the results in simulation manager, so I need to see as well the time-domain responses per multiple parameters, Is it possible to see/plot it in simulation manager?
Since I’m using "on-line" matlab version I can open Data Inspector I need to compare the responses of various model’s parametrs , I’m using the multiple simulations panel in the simulink editor to run multiple simulations with varying values. I’m viewing the results in simulation manager, so I need to see as well the time-domain responses per multiple parameters, Is it possible to see/plot it in simulation manager?
Since I’m using "on-line" matlab version I can open Data Inspector multiple simulation plot results MATLAB Answers — New Questions
using sparse matrix and vpa function simultaneously
i am using the following code in my 3D FEM analysis
digits(16)
k_bc=vpa(k_bc);
U=k_bcf_bc.
residual=norm(k_bc*U-f_bc).
Now to decrease the residual i have taken the variable to symbolic domain.Now when i use vpa i loose my sparcity of stiffness matrix causing a slow calculation rate but give lower value of residual and when i use sparse matrix the residual value is high because of the large condition number of k_bc of the order 10e14(i think it is a result of lagrange shape function beig used in Galerkin’s FEM).how to use both sparcity and vpa simultaneously to have lowervalue to residual and still have higher speedi am using the following code in my 3D FEM analysis
digits(16)
k_bc=vpa(k_bc);
U=k_bcf_bc.
residual=norm(k_bc*U-f_bc).
Now to decrease the residual i have taken the variable to symbolic domain.Now when i use vpa i loose my sparcity of stiffness matrix causing a slow calculation rate but give lower value of residual and when i use sparse matrix the residual value is high because of the large condition number of k_bc of the order 10e14(i think it is a result of lagrange shape function beig used in Galerkin’s FEM).how to use both sparcity and vpa simultaneously to have lowervalue to residual and still have higher speed i am using the following code in my 3D FEM analysis
digits(16)
k_bc=vpa(k_bc);
U=k_bcf_bc.
residual=norm(k_bc*U-f_bc).
Now to decrease the residual i have taken the variable to symbolic domain.Now when i use vpa i loose my sparcity of stiffness matrix causing a slow calculation rate but give lower value of residual and when i use sparse matrix the residual value is high because of the large condition number of k_bc of the order 10e14(i think it is a result of lagrange shape function beig used in Galerkin’s FEM).how to use both sparcity and vpa simultaneously to have lowervalue to residual and still have higher speed vpa, sparse MATLAB Answers — New Questions
How to control the speed of the synchronus motor in simscape?
I want to cntrol the speed of the synchronous motor , i used the spwm inverter circuit ans attached a synchronous motor but the motor is giving the speed in negative direction couls u please help me with this problem.I attached the model design and the output screen of the motor.I want to cntrol the speed of the synchronous motor , i used the spwm inverter circuit ans attached a synchronous motor but the motor is giving the speed in negative direction couls u please help me with this problem.I attached the model design and the output screen of the motor. I want to cntrol the speed of the synchronous motor , i used the spwm inverter circuit ans attached a synchronous motor but the motor is giving the speed in negative direction couls u please help me with this problem.I attached the model design and the output screen of the motor. control the speed of the motor MATLAB Answers — New Questions