Tag Archives: matlab
Interpolate pairs of values from matrix
I have a coarse 2D-matrix with [X,Y,Z]-values.
I want to input a Z-value and would like to interpolate possible values for the [X,Y]-pairs. These [X,Y]-pairs are then used for a fit. This means that for a given value of Z, if I choose any X value, Y can be calcualted and the other way arround.
I have tried the interp2 already, but it seems that I can only input X and Y values to get the interpolated Z value and not the other way around, where I input a Z-value and get a list of [X,Y]-pairs for that.
All the best
ChrisI have a coarse 2D-matrix with [X,Y,Z]-values.
I want to input a Z-value and would like to interpolate possible values for the [X,Y]-pairs. These [X,Y]-pairs are then used for a fit. This means that for a given value of Z, if I choose any X value, Y can be calcualted and the other way arround.
I have tried the interp2 already, but it seems that I can only input X and Y values to get the interpolated Z value and not the other way around, where I input a Z-value and get a list of [X,Y]-pairs for that.
All the best
Chris I have a coarse 2D-matrix with [X,Y,Z]-values.
I want to input a Z-value and would like to interpolate possible values for the [X,Y]-pairs. These [X,Y]-pairs are then used for a fit. This means that for a given value of Z, if I choose any X value, Y can be calcualted and the other way arround.
I have tried the interp2 already, but it seems that I can only input X and Y values to get the interpolated Z value and not the other way around, where I input a Z-value and get a list of [X,Y]-pairs for that.
All the best
Chris interp2 MATLAB Answers — New Questions
Drop down in uitable to work like excel
I have an uitable and I want to have certain cells with a drop down. I know that this is done by using the functions categorical and table. The problem is that I need the table to accept empty values and show the empty values as a blank cell with the drop down functionality. If I add the empty option to a categorical this will show as <undefined>
Data = cell(21,2);
for i = 1:length(Data)
for j = 1:length(Data)
Data{i,j} = "";
end
end
fig = uifigure;
tab = uitable(fig);
opts = categorical({‘1′,’2’,”});
Data{2,1} = opts(3);
Column1 = Data(:,1);
Column2 = Data(:,2);
tab.Data = table(Column1,Column2);
By making the Columns editable and changing the <undefined> value it will show always one of the non-empty options entered in the categorical function and not allowing the cell to be empty (or <undefined>) anymore:
Is there a way to allow this types of cells to work like the drop downs works in Excel?
Thank you beforehand.I have an uitable and I want to have certain cells with a drop down. I know that this is done by using the functions categorical and table. The problem is that I need the table to accept empty values and show the empty values as a blank cell with the drop down functionality. If I add the empty option to a categorical this will show as <undefined>
Data = cell(21,2);
for i = 1:length(Data)
for j = 1:length(Data)
Data{i,j} = "";
end
end
fig = uifigure;
tab = uitable(fig);
opts = categorical({‘1′,’2’,”});
Data{2,1} = opts(3);
Column1 = Data(:,1);
Column2 = Data(:,2);
tab.Data = table(Column1,Column2);
By making the Columns editable and changing the <undefined> value it will show always one of the non-empty options entered in the categorical function and not allowing the cell to be empty (or <undefined>) anymore:
Is there a way to allow this types of cells to work like the drop downs works in Excel?
Thank you beforehand. I have an uitable and I want to have certain cells with a drop down. I know that this is done by using the functions categorical and table. The problem is that I need the table to accept empty values and show the empty values as a blank cell with the drop down functionality. If I add the empty option to a categorical this will show as <undefined>
Data = cell(21,2);
for i = 1:length(Data)
for j = 1:length(Data)
Data{i,j} = "";
end
end
fig = uifigure;
tab = uitable(fig);
opts = categorical({‘1′,’2’,”});
Data{2,1} = opts(3);
Column1 = Data(:,1);
Column2 = Data(:,2);
tab.Data = table(Column1,Column2);
By making the Columns editable and changing the <undefined> value it will show always one of the non-empty options entered in the categorical function and not allowing the cell to be empty (or <undefined>) anymore:
Is there a way to allow this types of cells to work like the drop downs works in Excel?
Thank you beforehand. dropdown, uitable, excel, empty MATLAB Answers — New Questions
Error with simout = sim (…)
I have defined three signals with timeseries, then I want to simulate a model loading this three signals
I have a error with the function
simout = sim (‘model’, ‘LoadExternalInput’,’on’, ‘ExternalInput’,’inp’, ‘ExternalInput’,’inp1′,’ExternalInput’,’inp2′);
Error using model (line 41)
The number of external inputs must be equal to the number of root-level input port blocks. Root-level
input port blocks include Trigger and Enable blocks. The model contains 3 root-level input port
blocks, but 1 external inputs were specified in Configuration Parameters -> Data Import/Export ->
Input.
I don’t know why doesn’t recognize the signalsI have defined three signals with timeseries, then I want to simulate a model loading this three signals
I have a error with the function
simout = sim (‘model’, ‘LoadExternalInput’,’on’, ‘ExternalInput’,’inp’, ‘ExternalInput’,’inp1′,’ExternalInput’,’inp2′);
Error using model (line 41)
The number of external inputs must be equal to the number of root-level input port blocks. Root-level
input port blocks include Trigger and Enable blocks. The model contains 3 root-level input port
blocks, but 1 external inputs were specified in Configuration Parameters -> Data Import/Export ->
Input.
I don’t know why doesn’t recognize the signals I have defined three signals with timeseries, then I want to simulate a model loading this three signals
I have a error with the function
simout = sim (‘model’, ‘LoadExternalInput’,’on’, ‘ExternalInput’,’inp’, ‘ExternalInput’,’inp1′,’ExternalInput’,’inp2′);
Error using model (line 41)
The number of external inputs must be equal to the number of root-level input port blocks. Root-level
input port blocks include Trigger and Enable blocks. The model contains 3 root-level input port
blocks, but 1 external inputs were specified in Configuration Parameters -> Data Import/Export ->
Input.
I don’t know why doesn’t recognize the signals simout MATLAB Answers — New Questions
transform linear inequality constraints into bound constraints for optimization solvers
Suppose there are linear inequality constraints and are the parameters optimized by fmincon, lsqnonlin, or friends.
Since linear inequality constraints can generally not be enforced at intermediate iterations, I want to transform them into bound constraints which can be enforced at all iterations.
General idea:
If is dense and has rows (i.e, there are constraints), then we can make a "change of variables"
, where are the rows of , for instance, .
This leads to simple bound constraints . Does that make sense?
Specific problem:
My parameters represent interpolation values corresponding to interpolation points and the resulting interpolation function is supposed to be convex on the interpolation domain. For the specific case of linear interpolation, @Matt J showed that convexity is realized by increasing second order finite differences
(which represents a set of linear inequality constraints)
This can be transformed into simpler bounds on the new parameters by the change of variables
with
What I am really working with are smoother B-spline basis functions of higher degree using spapi function. @Bruno Luong showed that the linear inequality matrix is given by
% k: spline order, x: points where values y live
B = spapi(k,x,eye(length(x)));
Bdd = fnder(B,2);
A = Bdd.coefs’
and
is a sufficient condition for convexity.
I am wondering whether a change of variables (like for linear interpolation functions) can be applied here to transform the inequalities into bounds?
Any opinions are greatly appreciated!Suppose there are linear inequality constraints and are the parameters optimized by fmincon, lsqnonlin, or friends.
Since linear inequality constraints can generally not be enforced at intermediate iterations, I want to transform them into bound constraints which can be enforced at all iterations.
General idea:
If is dense and has rows (i.e, there are constraints), then we can make a "change of variables"
, where are the rows of , for instance, .
This leads to simple bound constraints . Does that make sense?
Specific problem:
My parameters represent interpolation values corresponding to interpolation points and the resulting interpolation function is supposed to be convex on the interpolation domain. For the specific case of linear interpolation, @Matt J showed that convexity is realized by increasing second order finite differences
(which represents a set of linear inequality constraints)
This can be transformed into simpler bounds on the new parameters by the change of variables
with
What I am really working with are smoother B-spline basis functions of higher degree using spapi function. @Bruno Luong showed that the linear inequality matrix is given by
% k: spline order, x: points where values y live
B = spapi(k,x,eye(length(x)));
Bdd = fnder(B,2);
A = Bdd.coefs’
and
is a sufficient condition for convexity.
I am wondering whether a change of variables (like for linear interpolation functions) can be applied here to transform the inequalities into bounds?
Any opinions are greatly appreciated! Suppose there are linear inequality constraints and are the parameters optimized by fmincon, lsqnonlin, or friends.
Since linear inequality constraints can generally not be enforced at intermediate iterations, I want to transform them into bound constraints which can be enforced at all iterations.
General idea:
If is dense and has rows (i.e, there are constraints), then we can make a "change of variables"
, where are the rows of , for instance, .
This leads to simple bound constraints . Does that make sense?
Specific problem:
My parameters represent interpolation values corresponding to interpolation points and the resulting interpolation function is supposed to be convex on the interpolation domain. For the specific case of linear interpolation, @Matt J showed that convexity is realized by increasing second order finite differences
(which represents a set of linear inequality constraints)
This can be transformed into simpler bounds on the new parameters by the change of variables
with
What I am really working with are smoother B-spline basis functions of higher degree using spapi function. @Bruno Luong showed that the linear inequality matrix is given by
% k: spline order, x: points where values y live
B = spapi(k,x,eye(length(x)));
Bdd = fnder(B,2);
A = Bdd.coefs’
and
is a sufficient condition for convexity.
I am wondering whether a change of variables (like for linear interpolation functions) can be applied here to transform the inequalities into bounds?
Any opinions are greatly appreciated! splines, optimization, fmincon, spapi, interpolation MATLAB Answers — New Questions
Colour representation of three matrices entities (SOLID, rho1 and rho2)
Dear friend,
Please I am solving a mixture of two fluids in a solid domain just as presented in the code below; I want a representation of the three parameters(SOLID,rho1 and rho2) with distinct colours in the same domain. Attached are two graphs (the one with two colours is the result I got, the result with three colours is what I want).
clear clc;close all;
% define numerical parameters
%new BounceBack<T,Descriptor>(0.5);
N=256;
nx=1*N; ny=N;
tau1=1; tau2=1; % relexation time
G=-1.5;
% define weight coefficient(D2Q9)
w0=4/9;
w1=1/9; w2=1/9; w3=1/9; w4=1/9;
w5=1/36; w6=1/36; w7=1/36; w8=1/36;
% initialize variable values in the field
c=1; %lattice speed
dt=1;% delta t
% solid capturing initialisation
SOLID=rand(nx+1,ny+1)>0.7;%extremely porous random domain
%SOLID = false( 1, nx, ny );
SOLID( 1, : ) = true;
SOLID( end, : ) = true;
SOLID( :, 1 ) = true;
SOLID( :, end ) = true;
%SOLID = find( SOLID );
% initialize distribution functions for two components
delta_rho=0.001*(1-2*rand(ny+1,nx+1));
rho1=1+delta_rho;
rho2=1-delta_rho;
% distribution function for component 1
f(:,:,1)=w1*rho1;
f(:,:,2)=w2*rho1;
f(:,:,3)=w3*rho1;
f(:,:,4)=w4*rho1;
f(:,:,5)=w5*rho1;
f(:,:,6)=w6*rho1;
f(:,:,7)=w7*rho1;
f(:,:,8)=w8*rho1;
f(:,:,9)=w0*rho1;
% distribution function for component 2
g(:,:,1)=w1*rho2;
g(:,:,2)=w2*rho2;
g(:,:,3)=w3*rho2;
g(:,:,4)=w4*rho2;
g(:,:,5)=w5*rho2;
g(:,:,6)=w6*rho2;
g(:,:,7)=w7*rho2;
g(:,:,8)=w8*rho2;
g(:,:,9)=w0*rho2;
for it=1:1000
% macropic properties
% calculate interaction body forces
rho1=sum(f,3); %density of fluid 1
rho2=sum(g,3); %density of fluid 2
rho_tot=rho1+rho2;% total local density
% body forces for conhension
F221_x=-rho1.*G.*(w1*circshift(rho2,[0,1])-w3*circshift(rho2,[0,-1])+w5*circshift(rho2,[-1,1])-w6*circshift(rho2,[-1,-1])…
-w7*circshift(rho2,[1,-1])+w8*circshift(rho2,[1,1]));
F221_y=-rho1.*G.*(w2*circshift(rho2,[-1 0])-w4*circshift(rho2,[1,0])+w5*circshift(rho2,[-1,1])+w6*circshift(rho2,[-1,-1])…
-w7*circshift(rho2,[1,-1])-w8*circshift(rho2,[1,1]));
F122_x=-rho2.*G.*(w1*circshift(rho1,[0,1])-w3*circshift(rho1,[0,-1])+w5*circshift(rho1,[-1,1])-w6*circshift(rho1,[-1,-1])…
-w7*circshift(rho1,[1,-1])+w8*circshift(rho1,[1,1]));
F122_y=-rho2.*G.*(w2*circshift(rho1,[-1 0])-w4*circshift(rho1,[1,0])+w5*circshift(rho1,[-1,1])+w6*circshift(rho1,[-1,-1])…
-w7*circshift(rho1,[1,-1])-w8*circshift(rho1,[1,1]));
% velocity field
u=(sum(f(:,:,[1 5 8]),3)-sum(f(:,:,[3 6 7]),3)+sum(g(:,:,[1 5 8]),3)-sum(g(:,:,[3 6 7]),3))./rho_tot+(F221_x+F122_x)./rho_tot./2;
v=(sum(f(:,:,[2 5 6]),3)-sum(f(:,:,[4 7 8]),3)+sum(g(:,:,[2 5 6]),3)-sum(g(:,:,[4 7 8]),3))./rho_tot+(F221_y+F122_y)./rho_tot./2;
% collision step
% calculate equilibrium distribution for fluid 1
feq(:,:,1)=w1*rho1.*(1+3*u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,2)=w2*rho1.*(1+3*v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,3)=w3*rho1.*(1+3*-u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,4)=w4*rho1.*(1+3*-v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,5)=w5*rho1.*(1+3*(u+v)/c+9/2*(u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,6)=w6*rho1.*(1+3*(-u+v)/c+9/2*(-u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,7)=w7*rho1.*(1+3*(-u-v)/c+9/2*(-u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,8)=w8*rho1.*(1+3*(u-v)/c+9/2*(u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,9)=w0*rho1.*(1-3/2*(u.^2+v.^2)/c^2);
% for fluid 2
geq(:,:,1)=w1*rho2.*(1+3*u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,2)=w2*rho2.*(1+3*v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,3)=w3*rho2.*(1+3*-u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,4)=w4*rho2.*(1+3*-v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,5)=w5*rho2.*(1+3*(u+v)/c+9/2*(u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,6)=w6*rho2.*(1+3*(-u+v)/c+9/2*(-u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,7)=w7*rho2.*(1+3*(-u-v)/c+9/2*(-u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,8)=w8*rho2.*(1+3*(u-v)/c+9/2*(u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,9)=w0*rho2.*(1-3/2*(u.^2+v.^2)/c^2);
%calculate body force terms in collision step
% for fluid 1
F1(:,:,1)=w1*(1-1/2/tau1)*((6*u+3).*(F221_x)+-3*v.*(F221_y));
F1(:,:,2)=w2*(1-1/2/tau1)*(-3*u.*(F221_x)+(3+6*v).*(F221_y));
F1(:,:,3)=w3*(1-1/2/tau1)*((6*u-3).*(F221_x)+-3*v.*(F221_y));
F1(:,:,4)=w4*(1-1/2/tau1)*(-3*u.*(F221_x)+(-3+6*v).*(F221_y));
F1(:,:,5)=w5*(1-1/2/tau1)*((3+6*u+9*v).*(F221_x)+(3+9*u+6*v).*(F221_y));
F1(:,:,6)=w6*(1-1/2/tau1)*((-3+6*u-9*v).*(F221_x)+(3-9*u+6*v).*(F221_y));
F1(:,:,7)=w7*(1-1/2/tau1)*((-3+6*u+9*v).*(F221_x)+(-3+9*u+6*v).*(F221_y));
F1(:,:,8)=w8*(1-1/2/tau1)*((3+6*u-9*v).*(F221_x)+(-3-9*u+6*v).*(F221_y));
F1(:,:,9)=w0*(1-1/2/tau1)*(-3*u.*(F221_x)+-3*v.*(F221_y));
% for fluid 2
F2(:,:,1)=w1*(1-1/2/tau2)*((6*u+3).*(F122_x)+-3*v.*(F122_y));
F2(:,:,2)=w2*(1-1/2/tau2)*(-3*u.*(F122_x)+(3+6*v).*(F122_y));
F2(:,:,3)=w3*(1-1/2/tau2)*((6*u-3).*(F122_x)+-3*v.*(F122_y));
F2(:,:,4)=w4*(1-1/2/tau2)*(-3*u.*(F122_x)+(-3+6*v).*(F122_y));
F2(:,:,5)=w5*(1-1/2/tau2)*((3+6*u+9*v).*(F122_x)+(3+9*u+6*v).*(F122_y));
F2(:,:,6)=w6*(1-1/2/tau2)*((-3+6*u-9*v).*(F122_x)+(3-9*u+6*v).*(F122_y));
F2(:,:,7)=w7*(1-1/2/tau2)*((-3+6*u+9*v).*(F122_x)+(-3+9*u+6*v).*(F122_y));
F2(:,:,8)=w8*(1-1/2/tau2)*((3+6*u-9*v).*(F122_x)+(-3-9*u+6*v).*(F122_y));
F2(:,:,9)=w0*(1-1/2/tau2)*(-3*u.*(F122_x)+-3*v.*(F122_y));
% collision
f=f-1/tau1.*(f-feq)+F1;
g=g-1/tau2.*(g-geq)+F2;
%streaming
f(:,:,1)=circshift(f(:,:,1),[0,1]);
f(:,:,2)=circshift(f(:,:,2),[-1,0]);
f(:,:,3)=circshift(f(:,:,3),[0,-1]);
f(:,:,4)=circshift(f(:,:,4),[1,0]);
f(:,:,5)=circshift(f(:,:,5),[-1,1]);
f(:,:,6)=circshift(f(:,:,6),[-1,-1]);
f(:,:,7)=circshift(f(:,:,7),[1,-1]);
f(:,:,8)=circshift(f(:,:,8),[1,1]);
g(:,:,1)=circshift(g(:,:,1),[0,1]);
g(:,:,2)=circshift(g(:,:,2),[-1,0]);
g(:,:,3)=circshift(g(:,:,3),[0,-1]);
g(:,:,4)=circshift(g(:,:,4),[1,0]);
g(:,:,5)=circshift(g(:,:,5),[-1,1]);
g(:,:,6)=circshift(g(:,:,6),[-1,-1]);
g(:,:,7)=circshift(g(:,:,7),[1,-1]);
g(:,:,8)=circshift(g(:,:,8),[1,1]);
% add BC
%L
f(:,1,1)=f(:,nx+1,1);
f(:,1,5)=f(:,nx+1,5);
f(:,1,8)=f(:,nx+1,8);
g(:,1,1)=g(:,nx+1,1);
g(:,1,5)=g(:,nx+1,5);
g(:,1,8)=g(:,nx+1,8);
%R
f(:,nx+1,3)=f(:,1,3);
f(:,nx+1,6)=f(:,1,6);
f(:,nx+1,7)=f(:,1,7);
g(:,nx+1,3)=g(:,1,3);
g(:,nx+1,6)=g(:,1,6);
g(:,nx+1,7)=g(:,1,7);
%T
f(1,:,4)=f(ny+1,:,4);
f(1,:,7)=f(ny+1,:,7);
f(1,:,8)=f(ny+1,:,8);
g(1,:,4)=g(ny+1,:,4);
g(1,:,7)=g(ny+1,:,7);
g(1,:,8)=g(ny+1,:,8);
%B
f(ny+1,:,2)=f(1,:,2);
f(ny+1,:,5)=f(1,:,5);
f(ny+1,:,6)=f(1,:,6);
g(ny+1,:,2)=g(1,:,2);
g(ny+1,:,5)=g(1,:,5);
g(ny+1,:,6)=g(1,:,6);
if rem(it,5)==0
imagesc(rho1);
%imagesc(rho2);
%imagesc(solid);
fff=getframe;
axis equal off;
end
endDear friend,
Please I am solving a mixture of two fluids in a solid domain just as presented in the code below; I want a representation of the three parameters(SOLID,rho1 and rho2) with distinct colours in the same domain. Attached are two graphs (the one with two colours is the result I got, the result with three colours is what I want).
clear clc;close all;
% define numerical parameters
%new BounceBack<T,Descriptor>(0.5);
N=256;
nx=1*N; ny=N;
tau1=1; tau2=1; % relexation time
G=-1.5;
% define weight coefficient(D2Q9)
w0=4/9;
w1=1/9; w2=1/9; w3=1/9; w4=1/9;
w5=1/36; w6=1/36; w7=1/36; w8=1/36;
% initialize variable values in the field
c=1; %lattice speed
dt=1;% delta t
% solid capturing initialisation
SOLID=rand(nx+1,ny+1)>0.7;%extremely porous random domain
%SOLID = false( 1, nx, ny );
SOLID( 1, : ) = true;
SOLID( end, : ) = true;
SOLID( :, 1 ) = true;
SOLID( :, end ) = true;
%SOLID = find( SOLID );
% initialize distribution functions for two components
delta_rho=0.001*(1-2*rand(ny+1,nx+1));
rho1=1+delta_rho;
rho2=1-delta_rho;
% distribution function for component 1
f(:,:,1)=w1*rho1;
f(:,:,2)=w2*rho1;
f(:,:,3)=w3*rho1;
f(:,:,4)=w4*rho1;
f(:,:,5)=w5*rho1;
f(:,:,6)=w6*rho1;
f(:,:,7)=w7*rho1;
f(:,:,8)=w8*rho1;
f(:,:,9)=w0*rho1;
% distribution function for component 2
g(:,:,1)=w1*rho2;
g(:,:,2)=w2*rho2;
g(:,:,3)=w3*rho2;
g(:,:,4)=w4*rho2;
g(:,:,5)=w5*rho2;
g(:,:,6)=w6*rho2;
g(:,:,7)=w7*rho2;
g(:,:,8)=w8*rho2;
g(:,:,9)=w0*rho2;
for it=1:1000
% macropic properties
% calculate interaction body forces
rho1=sum(f,3); %density of fluid 1
rho2=sum(g,3); %density of fluid 2
rho_tot=rho1+rho2;% total local density
% body forces for conhension
F221_x=-rho1.*G.*(w1*circshift(rho2,[0,1])-w3*circshift(rho2,[0,-1])+w5*circshift(rho2,[-1,1])-w6*circshift(rho2,[-1,-1])…
-w7*circshift(rho2,[1,-1])+w8*circshift(rho2,[1,1]));
F221_y=-rho1.*G.*(w2*circshift(rho2,[-1 0])-w4*circshift(rho2,[1,0])+w5*circshift(rho2,[-1,1])+w6*circshift(rho2,[-1,-1])…
-w7*circshift(rho2,[1,-1])-w8*circshift(rho2,[1,1]));
F122_x=-rho2.*G.*(w1*circshift(rho1,[0,1])-w3*circshift(rho1,[0,-1])+w5*circshift(rho1,[-1,1])-w6*circshift(rho1,[-1,-1])…
-w7*circshift(rho1,[1,-1])+w8*circshift(rho1,[1,1]));
F122_y=-rho2.*G.*(w2*circshift(rho1,[-1 0])-w4*circshift(rho1,[1,0])+w5*circshift(rho1,[-1,1])+w6*circshift(rho1,[-1,-1])…
-w7*circshift(rho1,[1,-1])-w8*circshift(rho1,[1,1]));
% velocity field
u=(sum(f(:,:,[1 5 8]),3)-sum(f(:,:,[3 6 7]),3)+sum(g(:,:,[1 5 8]),3)-sum(g(:,:,[3 6 7]),3))./rho_tot+(F221_x+F122_x)./rho_tot./2;
v=(sum(f(:,:,[2 5 6]),3)-sum(f(:,:,[4 7 8]),3)+sum(g(:,:,[2 5 6]),3)-sum(g(:,:,[4 7 8]),3))./rho_tot+(F221_y+F122_y)./rho_tot./2;
% collision step
% calculate equilibrium distribution for fluid 1
feq(:,:,1)=w1*rho1.*(1+3*u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,2)=w2*rho1.*(1+3*v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,3)=w3*rho1.*(1+3*-u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,4)=w4*rho1.*(1+3*-v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,5)=w5*rho1.*(1+3*(u+v)/c+9/2*(u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,6)=w6*rho1.*(1+3*(-u+v)/c+9/2*(-u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,7)=w7*rho1.*(1+3*(-u-v)/c+9/2*(-u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,8)=w8*rho1.*(1+3*(u-v)/c+9/2*(u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,9)=w0*rho1.*(1-3/2*(u.^2+v.^2)/c^2);
% for fluid 2
geq(:,:,1)=w1*rho2.*(1+3*u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,2)=w2*rho2.*(1+3*v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,3)=w3*rho2.*(1+3*-u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,4)=w4*rho2.*(1+3*-v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,5)=w5*rho2.*(1+3*(u+v)/c+9/2*(u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,6)=w6*rho2.*(1+3*(-u+v)/c+9/2*(-u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,7)=w7*rho2.*(1+3*(-u-v)/c+9/2*(-u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,8)=w8*rho2.*(1+3*(u-v)/c+9/2*(u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,9)=w0*rho2.*(1-3/2*(u.^2+v.^2)/c^2);
%calculate body force terms in collision step
% for fluid 1
F1(:,:,1)=w1*(1-1/2/tau1)*((6*u+3).*(F221_x)+-3*v.*(F221_y));
F1(:,:,2)=w2*(1-1/2/tau1)*(-3*u.*(F221_x)+(3+6*v).*(F221_y));
F1(:,:,3)=w3*(1-1/2/tau1)*((6*u-3).*(F221_x)+-3*v.*(F221_y));
F1(:,:,4)=w4*(1-1/2/tau1)*(-3*u.*(F221_x)+(-3+6*v).*(F221_y));
F1(:,:,5)=w5*(1-1/2/tau1)*((3+6*u+9*v).*(F221_x)+(3+9*u+6*v).*(F221_y));
F1(:,:,6)=w6*(1-1/2/tau1)*((-3+6*u-9*v).*(F221_x)+(3-9*u+6*v).*(F221_y));
F1(:,:,7)=w7*(1-1/2/tau1)*((-3+6*u+9*v).*(F221_x)+(-3+9*u+6*v).*(F221_y));
F1(:,:,8)=w8*(1-1/2/tau1)*((3+6*u-9*v).*(F221_x)+(-3-9*u+6*v).*(F221_y));
F1(:,:,9)=w0*(1-1/2/tau1)*(-3*u.*(F221_x)+-3*v.*(F221_y));
% for fluid 2
F2(:,:,1)=w1*(1-1/2/tau2)*((6*u+3).*(F122_x)+-3*v.*(F122_y));
F2(:,:,2)=w2*(1-1/2/tau2)*(-3*u.*(F122_x)+(3+6*v).*(F122_y));
F2(:,:,3)=w3*(1-1/2/tau2)*((6*u-3).*(F122_x)+-3*v.*(F122_y));
F2(:,:,4)=w4*(1-1/2/tau2)*(-3*u.*(F122_x)+(-3+6*v).*(F122_y));
F2(:,:,5)=w5*(1-1/2/tau2)*((3+6*u+9*v).*(F122_x)+(3+9*u+6*v).*(F122_y));
F2(:,:,6)=w6*(1-1/2/tau2)*((-3+6*u-9*v).*(F122_x)+(3-9*u+6*v).*(F122_y));
F2(:,:,7)=w7*(1-1/2/tau2)*((-3+6*u+9*v).*(F122_x)+(-3+9*u+6*v).*(F122_y));
F2(:,:,8)=w8*(1-1/2/tau2)*((3+6*u-9*v).*(F122_x)+(-3-9*u+6*v).*(F122_y));
F2(:,:,9)=w0*(1-1/2/tau2)*(-3*u.*(F122_x)+-3*v.*(F122_y));
% collision
f=f-1/tau1.*(f-feq)+F1;
g=g-1/tau2.*(g-geq)+F2;
%streaming
f(:,:,1)=circshift(f(:,:,1),[0,1]);
f(:,:,2)=circshift(f(:,:,2),[-1,0]);
f(:,:,3)=circshift(f(:,:,3),[0,-1]);
f(:,:,4)=circshift(f(:,:,4),[1,0]);
f(:,:,5)=circshift(f(:,:,5),[-1,1]);
f(:,:,6)=circshift(f(:,:,6),[-1,-1]);
f(:,:,7)=circshift(f(:,:,7),[1,-1]);
f(:,:,8)=circshift(f(:,:,8),[1,1]);
g(:,:,1)=circshift(g(:,:,1),[0,1]);
g(:,:,2)=circshift(g(:,:,2),[-1,0]);
g(:,:,3)=circshift(g(:,:,3),[0,-1]);
g(:,:,4)=circshift(g(:,:,4),[1,0]);
g(:,:,5)=circshift(g(:,:,5),[-1,1]);
g(:,:,6)=circshift(g(:,:,6),[-1,-1]);
g(:,:,7)=circshift(g(:,:,7),[1,-1]);
g(:,:,8)=circshift(g(:,:,8),[1,1]);
% add BC
%L
f(:,1,1)=f(:,nx+1,1);
f(:,1,5)=f(:,nx+1,5);
f(:,1,8)=f(:,nx+1,8);
g(:,1,1)=g(:,nx+1,1);
g(:,1,5)=g(:,nx+1,5);
g(:,1,8)=g(:,nx+1,8);
%R
f(:,nx+1,3)=f(:,1,3);
f(:,nx+1,6)=f(:,1,6);
f(:,nx+1,7)=f(:,1,7);
g(:,nx+1,3)=g(:,1,3);
g(:,nx+1,6)=g(:,1,6);
g(:,nx+1,7)=g(:,1,7);
%T
f(1,:,4)=f(ny+1,:,4);
f(1,:,7)=f(ny+1,:,7);
f(1,:,8)=f(ny+1,:,8);
g(1,:,4)=g(ny+1,:,4);
g(1,:,7)=g(ny+1,:,7);
g(1,:,8)=g(ny+1,:,8);
%B
f(ny+1,:,2)=f(1,:,2);
f(ny+1,:,5)=f(1,:,5);
f(ny+1,:,6)=f(1,:,6);
g(ny+1,:,2)=g(1,:,2);
g(ny+1,:,5)=g(1,:,5);
g(ny+1,:,6)=g(1,:,6);
if rem(it,5)==0
imagesc(rho1);
%imagesc(rho2);
%imagesc(solid);
fff=getframe;
axis equal off;
end
end Dear friend,
Please I am solving a mixture of two fluids in a solid domain just as presented in the code below; I want a representation of the three parameters(SOLID,rho1 and rho2) with distinct colours in the same domain. Attached are two graphs (the one with two colours is the result I got, the result with three colours is what I want).
clear clc;close all;
% define numerical parameters
%new BounceBack<T,Descriptor>(0.5);
N=256;
nx=1*N; ny=N;
tau1=1; tau2=1; % relexation time
G=-1.5;
% define weight coefficient(D2Q9)
w0=4/9;
w1=1/9; w2=1/9; w3=1/9; w4=1/9;
w5=1/36; w6=1/36; w7=1/36; w8=1/36;
% initialize variable values in the field
c=1; %lattice speed
dt=1;% delta t
% solid capturing initialisation
SOLID=rand(nx+1,ny+1)>0.7;%extremely porous random domain
%SOLID = false( 1, nx, ny );
SOLID( 1, : ) = true;
SOLID( end, : ) = true;
SOLID( :, 1 ) = true;
SOLID( :, end ) = true;
%SOLID = find( SOLID );
% initialize distribution functions for two components
delta_rho=0.001*(1-2*rand(ny+1,nx+1));
rho1=1+delta_rho;
rho2=1-delta_rho;
% distribution function for component 1
f(:,:,1)=w1*rho1;
f(:,:,2)=w2*rho1;
f(:,:,3)=w3*rho1;
f(:,:,4)=w4*rho1;
f(:,:,5)=w5*rho1;
f(:,:,6)=w6*rho1;
f(:,:,7)=w7*rho1;
f(:,:,8)=w8*rho1;
f(:,:,9)=w0*rho1;
% distribution function for component 2
g(:,:,1)=w1*rho2;
g(:,:,2)=w2*rho2;
g(:,:,3)=w3*rho2;
g(:,:,4)=w4*rho2;
g(:,:,5)=w5*rho2;
g(:,:,6)=w6*rho2;
g(:,:,7)=w7*rho2;
g(:,:,8)=w8*rho2;
g(:,:,9)=w0*rho2;
for it=1:1000
% macropic properties
% calculate interaction body forces
rho1=sum(f,3); %density of fluid 1
rho2=sum(g,3); %density of fluid 2
rho_tot=rho1+rho2;% total local density
% body forces for conhension
F221_x=-rho1.*G.*(w1*circshift(rho2,[0,1])-w3*circshift(rho2,[0,-1])+w5*circshift(rho2,[-1,1])-w6*circshift(rho2,[-1,-1])…
-w7*circshift(rho2,[1,-1])+w8*circshift(rho2,[1,1]));
F221_y=-rho1.*G.*(w2*circshift(rho2,[-1 0])-w4*circshift(rho2,[1,0])+w5*circshift(rho2,[-1,1])+w6*circshift(rho2,[-1,-1])…
-w7*circshift(rho2,[1,-1])-w8*circshift(rho2,[1,1]));
F122_x=-rho2.*G.*(w1*circshift(rho1,[0,1])-w3*circshift(rho1,[0,-1])+w5*circshift(rho1,[-1,1])-w6*circshift(rho1,[-1,-1])…
-w7*circshift(rho1,[1,-1])+w8*circshift(rho1,[1,1]));
F122_y=-rho2.*G.*(w2*circshift(rho1,[-1 0])-w4*circshift(rho1,[1,0])+w5*circshift(rho1,[-1,1])+w6*circshift(rho1,[-1,-1])…
-w7*circshift(rho1,[1,-1])-w8*circshift(rho1,[1,1]));
% velocity field
u=(sum(f(:,:,[1 5 8]),3)-sum(f(:,:,[3 6 7]),3)+sum(g(:,:,[1 5 8]),3)-sum(g(:,:,[3 6 7]),3))./rho_tot+(F221_x+F122_x)./rho_tot./2;
v=(sum(f(:,:,[2 5 6]),3)-sum(f(:,:,[4 7 8]),3)+sum(g(:,:,[2 5 6]),3)-sum(g(:,:,[4 7 8]),3))./rho_tot+(F221_y+F122_y)./rho_tot./2;
% collision step
% calculate equilibrium distribution for fluid 1
feq(:,:,1)=w1*rho1.*(1+3*u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,2)=w2*rho1.*(1+3*v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,3)=w3*rho1.*(1+3*-u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,4)=w4*rho1.*(1+3*-v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,5)=w5*rho1.*(1+3*(u+v)/c+9/2*(u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,6)=w6*rho1.*(1+3*(-u+v)/c+9/2*(-u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,7)=w7*rho1.*(1+3*(-u-v)/c+9/2*(-u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,8)=w8*rho1.*(1+3*(u-v)/c+9/2*(u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
feq(:,:,9)=w0*rho1.*(1-3/2*(u.^2+v.^2)/c^2);
% for fluid 2
geq(:,:,1)=w1*rho2.*(1+3*u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,2)=w2*rho2.*(1+3*v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,3)=w3*rho2.*(1+3*-u/c+9/2*u.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,4)=w4*rho2.*(1+3*-v/c+9/2*v.^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,5)=w5*rho2.*(1+3*(u+v)/c+9/2*(u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,6)=w6*rho2.*(1+3*(-u+v)/c+9/2*(-u+v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,7)=w7*rho2.*(1+3*(-u-v)/c+9/2*(-u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,8)=w8*rho2.*(1+3*(u-v)/c+9/2*(u-v).^2/c^2-3/2*(u.^2+v.^2)/c^2);
geq(:,:,9)=w0*rho2.*(1-3/2*(u.^2+v.^2)/c^2);
%calculate body force terms in collision step
% for fluid 1
F1(:,:,1)=w1*(1-1/2/tau1)*((6*u+3).*(F221_x)+-3*v.*(F221_y));
F1(:,:,2)=w2*(1-1/2/tau1)*(-3*u.*(F221_x)+(3+6*v).*(F221_y));
F1(:,:,3)=w3*(1-1/2/tau1)*((6*u-3).*(F221_x)+-3*v.*(F221_y));
F1(:,:,4)=w4*(1-1/2/tau1)*(-3*u.*(F221_x)+(-3+6*v).*(F221_y));
F1(:,:,5)=w5*(1-1/2/tau1)*((3+6*u+9*v).*(F221_x)+(3+9*u+6*v).*(F221_y));
F1(:,:,6)=w6*(1-1/2/tau1)*((-3+6*u-9*v).*(F221_x)+(3-9*u+6*v).*(F221_y));
F1(:,:,7)=w7*(1-1/2/tau1)*((-3+6*u+9*v).*(F221_x)+(-3+9*u+6*v).*(F221_y));
F1(:,:,8)=w8*(1-1/2/tau1)*((3+6*u-9*v).*(F221_x)+(-3-9*u+6*v).*(F221_y));
F1(:,:,9)=w0*(1-1/2/tau1)*(-3*u.*(F221_x)+-3*v.*(F221_y));
% for fluid 2
F2(:,:,1)=w1*(1-1/2/tau2)*((6*u+3).*(F122_x)+-3*v.*(F122_y));
F2(:,:,2)=w2*(1-1/2/tau2)*(-3*u.*(F122_x)+(3+6*v).*(F122_y));
F2(:,:,3)=w3*(1-1/2/tau2)*((6*u-3).*(F122_x)+-3*v.*(F122_y));
F2(:,:,4)=w4*(1-1/2/tau2)*(-3*u.*(F122_x)+(-3+6*v).*(F122_y));
F2(:,:,5)=w5*(1-1/2/tau2)*((3+6*u+9*v).*(F122_x)+(3+9*u+6*v).*(F122_y));
F2(:,:,6)=w6*(1-1/2/tau2)*((-3+6*u-9*v).*(F122_x)+(3-9*u+6*v).*(F122_y));
F2(:,:,7)=w7*(1-1/2/tau2)*((-3+6*u+9*v).*(F122_x)+(-3+9*u+6*v).*(F122_y));
F2(:,:,8)=w8*(1-1/2/tau2)*((3+6*u-9*v).*(F122_x)+(-3-9*u+6*v).*(F122_y));
F2(:,:,9)=w0*(1-1/2/tau2)*(-3*u.*(F122_x)+-3*v.*(F122_y));
% collision
f=f-1/tau1.*(f-feq)+F1;
g=g-1/tau2.*(g-geq)+F2;
%streaming
f(:,:,1)=circshift(f(:,:,1),[0,1]);
f(:,:,2)=circshift(f(:,:,2),[-1,0]);
f(:,:,3)=circshift(f(:,:,3),[0,-1]);
f(:,:,4)=circshift(f(:,:,4),[1,0]);
f(:,:,5)=circshift(f(:,:,5),[-1,1]);
f(:,:,6)=circshift(f(:,:,6),[-1,-1]);
f(:,:,7)=circshift(f(:,:,7),[1,-1]);
f(:,:,8)=circshift(f(:,:,8),[1,1]);
g(:,:,1)=circshift(g(:,:,1),[0,1]);
g(:,:,2)=circshift(g(:,:,2),[-1,0]);
g(:,:,3)=circshift(g(:,:,3),[0,-1]);
g(:,:,4)=circshift(g(:,:,4),[1,0]);
g(:,:,5)=circshift(g(:,:,5),[-1,1]);
g(:,:,6)=circshift(g(:,:,6),[-1,-1]);
g(:,:,7)=circshift(g(:,:,7),[1,-1]);
g(:,:,8)=circshift(g(:,:,8),[1,1]);
% add BC
%L
f(:,1,1)=f(:,nx+1,1);
f(:,1,5)=f(:,nx+1,5);
f(:,1,8)=f(:,nx+1,8);
g(:,1,1)=g(:,nx+1,1);
g(:,1,5)=g(:,nx+1,5);
g(:,1,8)=g(:,nx+1,8);
%R
f(:,nx+1,3)=f(:,1,3);
f(:,nx+1,6)=f(:,1,6);
f(:,nx+1,7)=f(:,1,7);
g(:,nx+1,3)=g(:,1,3);
g(:,nx+1,6)=g(:,1,6);
g(:,nx+1,7)=g(:,1,7);
%T
f(1,:,4)=f(ny+1,:,4);
f(1,:,7)=f(ny+1,:,7);
f(1,:,8)=f(ny+1,:,8);
g(1,:,4)=g(ny+1,:,4);
g(1,:,7)=g(ny+1,:,7);
g(1,:,8)=g(ny+1,:,8);
%B
f(ny+1,:,2)=f(1,:,2);
f(ny+1,:,5)=f(1,:,5);
f(ny+1,:,6)=f(1,:,6);
g(ny+1,:,2)=g(1,:,2);
g(ny+1,:,5)=g(1,:,5);
g(ny+1,:,6)=g(1,:,6);
if rem(it,5)==0
imagesc(rho1);
%imagesc(rho2);
%imagesc(solid);
fff=getframe;
axis equal off;
end
end the parameters in the same domain MATLAB Answers — New Questions
Cannot define a cell array of custom classes in function argument validation
I’ve a class like the following one:
classdef Session < handle
%SESSION Summary of this class goes here
% Detailed explanation goes here
properties (Access = private)
configurations (1, 🙂 cell {mustBeA(configurations, "App.Core.Configuration")}
end
methods (Access = public)
function this = Session()
this.configurations = {}
end
end
What I want to do is to declare che configuration property as a unidimensional cell array of a custom class, that can have 0 or more elements.
The problem is that I cannot instantiate it. When I try to do something like:
s = App.Core.Session()
I obtain the following error
Error using implicit default value of property ‘configurations’ of class ‘App.Core.Session’. Value must be one of the following types: ‘App.Core.Configuration’.
even if the App.Core.Configuration() class exists and it works (I’ve already unit tested it).
How can I declare correctly my configurations property?I’ve a class like the following one:
classdef Session < handle
%SESSION Summary of this class goes here
% Detailed explanation goes here
properties (Access = private)
configurations (1, 🙂 cell {mustBeA(configurations, "App.Core.Configuration")}
end
methods (Access = public)
function this = Session()
this.configurations = {}
end
end
What I want to do is to declare che configuration property as a unidimensional cell array of a custom class, that can have 0 or more elements.
The problem is that I cannot instantiate it. When I try to do something like:
s = App.Core.Session()
I obtain the following error
Error using implicit default value of property ‘configurations’ of class ‘App.Core.Session’. Value must be one of the following types: ‘App.Core.Configuration’.
even if the App.Core.Configuration() class exists and it works (I’ve already unit tested it).
How can I declare correctly my configurations property? I’ve a class like the following one:
classdef Session < handle
%SESSION Summary of this class goes here
% Detailed explanation goes here
properties (Access = private)
configurations (1, 🙂 cell {mustBeA(configurations, "App.Core.Configuration")}
end
methods (Access = public)
function this = Session()
this.configurations = {}
end
end
What I want to do is to declare che configuration property as a unidimensional cell array of a custom class, that can have 0 or more elements.
The problem is that I cannot instantiate it. When I try to do something like:
s = App.Core.Session()
I obtain the following error
Error using implicit default value of property ‘configurations’ of class ‘App.Core.Session’. Value must be one of the following types: ‘App.Core.Configuration’.
even if the App.Core.Configuration() class exists and it works (I’ve already unit tested it).
How can I declare correctly my configurations property? validation, class, cell, mustbea MATLAB Answers — New Questions
Matlab If Else Statement
The prompt of the question I have to do is: " The value of y is defined in terms of x by y=ln(0.5-x), write a function myfun(x) that takes some value x and does the following:
If x is greater or equal to 0.5 the function should caluculate y by using the negative value of that x and assign the result to z
If the value of x smaller than 0.5 the function should return the value z where z is calculated as the following
z=y^n
where n is (x+(100*x)) rounded to the nearest integer.
In my code, under a new scipt I created the function saved as "myfunx" as follows;
function myfun(x)
if x>=0.5
y=ln(0.5-(-x))
z=y^n
else
y=ln(0.5-x)
z=y^n
end
and in the command window when I test it with such value as x=1 and call the funciton myfunx, and it reads error and claims
"Not enough input arguments.
Error in myfunx (line2)
if x>=0.5
However I do not know what Im doing wrong or how I could fix this, any tips or ideas that could help me solve this would be appreciated thank you!The prompt of the question I have to do is: " The value of y is defined in terms of x by y=ln(0.5-x), write a function myfun(x) that takes some value x and does the following:
If x is greater or equal to 0.5 the function should caluculate y by using the negative value of that x and assign the result to z
If the value of x smaller than 0.5 the function should return the value z where z is calculated as the following
z=y^n
where n is (x+(100*x)) rounded to the nearest integer.
In my code, under a new scipt I created the function saved as "myfunx" as follows;
function myfun(x)
if x>=0.5
y=ln(0.5-(-x))
z=y^n
else
y=ln(0.5-x)
z=y^n
end
and in the command window when I test it with such value as x=1 and call the funciton myfunx, and it reads error and claims
"Not enough input arguments.
Error in myfunx (line2)
if x>=0.5
However I do not know what Im doing wrong or how I could fix this, any tips or ideas that could help me solve this would be appreciated thank you! The prompt of the question I have to do is: " The value of y is defined in terms of x by y=ln(0.5-x), write a function myfun(x) that takes some value x and does the following:
If x is greater or equal to 0.5 the function should caluculate y by using the negative value of that x and assign the result to z
If the value of x smaller than 0.5 the function should return the value z where z is calculated as the following
z=y^n
where n is (x+(100*x)) rounded to the nearest integer.
In my code, under a new scipt I created the function saved as "myfunx" as follows;
function myfun(x)
if x>=0.5
y=ln(0.5-(-x))
z=y^n
else
y=ln(0.5-x)
z=y^n
end
and in the command window when I test it with such value as x=1 and call the funciton myfunx, and it reads error and claims
"Not enough input arguments.
Error in myfunx (line2)
if x>=0.5
However I do not know what Im doing wrong or how I could fix this, any tips or ideas that could help me solve this would be appreciated thank you! if statement, if else MATLAB Answers — New Questions
After each restart, the parameters of the multimeter blocks change randomly (Simulink Simscape Electrical – Specialized Power Systems)
Hey everyone,
I am currently using Simulink Simscape Electrical Specialized Power Systems extensively for my work. However, I have encountered a persistent issue that I find quite bothersome.
In order to perform measurements of voltages, currents, etc., I rely on several multimeter blocks. Unfortunately, after each program restart, the output parameters/measurement parameters of these multimeter blocks change randomly. As a result, I have to reconfigure the multimeter blocks every time I restart the program. This process is quite cumbersome and time-consuming.
I was wondering if any of you have experienced the same or a similar issue and could provide me with some guidance or assistance in resolving it.
Thank you in advance for your help.
Best regards,
TorbenHey everyone,
I am currently using Simulink Simscape Electrical Specialized Power Systems extensively for my work. However, I have encountered a persistent issue that I find quite bothersome.
In order to perform measurements of voltages, currents, etc., I rely on several multimeter blocks. Unfortunately, after each program restart, the output parameters/measurement parameters of these multimeter blocks change randomly. As a result, I have to reconfigure the multimeter blocks every time I restart the program. This process is quite cumbersome and time-consuming.
I was wondering if any of you have experienced the same or a similar issue and could provide me with some guidance or assistance in resolving it.
Thank you in advance for your help.
Best regards,
Torben Hey everyone,
I am currently using Simulink Simscape Electrical Specialized Power Systems extensively for my work. However, I have encountered a persistent issue that I find quite bothersome.
In order to perform measurements of voltages, currents, etc., I rely on several multimeter blocks. Unfortunately, after each program restart, the output parameters/measurement parameters of these multimeter blocks change randomly. As a result, I have to reconfigure the multimeter blocks every time I restart the program. This process is quite cumbersome and time-consuming.
I was wondering if any of you have experienced the same or a similar issue and could provide me with some guidance or assistance in resolving it.
Thank you in advance for your help.
Best regards,
Torben multimeter, simulink simscape electrical, specialized power systems MATLAB Answers — New Questions
Scalable IoT data collection
Hi everyone,
I need someone to assist me toward simulating real-time IoT data collection using ThinkSpeak on online kaggle datasetsHi everyone,
I need someone to assist me toward simulating real-time IoT data collection using ThinkSpeak on online kaggle datasets Hi everyone,
I need someone to assist me toward simulating real-time IoT data collection using ThinkSpeak on online kaggle datasets transferred MATLAB Answers — New Questions
is it possible to display the size of an image in MB or KB on matlab?????? if yes how??
plezzz hel asap!!plezzz hel asap!! plezzz hel asap!! image processing MATLAB Answers — New Questions
To improve results using GA toolbox
Hi all, I solved a optimization problem using GA toolbox, but I am not getting desired answer using GA. I tried lots of setting and I got littlebit better results. But there is very small change in the fittness function value after few generation. Can anybody help me in this regard? How to improve the results?
Thank youHi all, I solved a optimization problem using GA toolbox, but I am not getting desired answer using GA. I tried lots of setting and I got littlebit better results. But there is very small change in the fittness function value after few generation. Can anybody help me in this regard? How to improve the results?
Thank you Hi all, I solved a optimization problem using GA toolbox, but I am not getting desired answer using GA. I tried lots of setting and I got littlebit better results. But there is very small change in the fittness function value after few generation. Can anybody help me in this regard? How to improve the results?
Thank you ga toolbox, results MATLAB Answers — New Questions
Why is my function not recognized?
Greetings! I’ve written the following MATLAB script:
CorrectAnswers=[‘B’ ‘D’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
%These are the correct answers for a quiz. There are ten questions on the quiz.
Claire=[‘B’ ‘D’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
Oliver=[‘A’ ‘C’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘A’];
Lana=[‘B’ ‘D’ ‘B’ ‘A’ ‘C’ ‘B’ ‘D’ ‘B’ ‘C’ ‘B’];
Abbie=[‘B’ ‘B’ ‘A’ ‘C’ ‘C’ ‘B’ ‘D’ ‘A’ ‘D’ ‘B’];
Kevin=[‘B’ ‘D’ ‘A’ ‘A’ ‘D’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
%These are the answers five different students gave.
function [StudentScore]=CheckScore(StudentAnswers)
StudentScore=0;
for k=1:10
if StudentAnswers(k)==CorrectAnswers(k)
StudentScore=StudentScore+10;
end
end
disp(StudentScore)
end
%The above function checks if a student’s answers match the correct
%answers, which are defined in the vector "CorrectAnswers". The score
%increases by 10 for each matching answer.
When writing, I received the following error in the script file: "Line 11: Function might be unused." For reference, Line 11 is shown below:
function [StudentScore]=CheckScore(StudentAnswers)
When I go to the Command Window to call the function "CheckScore", like below, this is the result:
>> CheckScore(Oliver)
Unrecognized function or variable ‘CheckScore’.
I’m not sure why "CheckScore" is undefined, when I (think I) defined it as a for loop within the function code. I feel like there’s a very simple fix for this, but I can’t for the life of me figure it out. Any help is appreciated, and thank you for your time!Greetings! I’ve written the following MATLAB script:
CorrectAnswers=[‘B’ ‘D’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
%These are the correct answers for a quiz. There are ten questions on the quiz.
Claire=[‘B’ ‘D’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
Oliver=[‘A’ ‘C’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘A’];
Lana=[‘B’ ‘D’ ‘B’ ‘A’ ‘C’ ‘B’ ‘D’ ‘B’ ‘C’ ‘B’];
Abbie=[‘B’ ‘B’ ‘A’ ‘C’ ‘C’ ‘B’ ‘D’ ‘A’ ‘D’ ‘B’];
Kevin=[‘B’ ‘D’ ‘A’ ‘A’ ‘D’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
%These are the answers five different students gave.
function [StudentScore]=CheckScore(StudentAnswers)
StudentScore=0;
for k=1:10
if StudentAnswers(k)==CorrectAnswers(k)
StudentScore=StudentScore+10;
end
end
disp(StudentScore)
end
%The above function checks if a student’s answers match the correct
%answers, which are defined in the vector "CorrectAnswers". The score
%increases by 10 for each matching answer.
When writing, I received the following error in the script file: "Line 11: Function might be unused." For reference, Line 11 is shown below:
function [StudentScore]=CheckScore(StudentAnswers)
When I go to the Command Window to call the function "CheckScore", like below, this is the result:
>> CheckScore(Oliver)
Unrecognized function or variable ‘CheckScore’.
I’m not sure why "CheckScore" is undefined, when I (think I) defined it as a for loop within the function code. I feel like there’s a very simple fix for this, but I can’t for the life of me figure it out. Any help is appreciated, and thank you for your time! Greetings! I’ve written the following MATLAB script:
CorrectAnswers=[‘B’ ‘D’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
%These are the correct answers for a quiz. There are ten questions on the quiz.
Claire=[‘B’ ‘D’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
Oliver=[‘A’ ‘C’ ‘A’ ‘A’ ‘C’ ‘B’ ‘D’ ‘A’ ‘C’ ‘A’];
Lana=[‘B’ ‘D’ ‘B’ ‘A’ ‘C’ ‘B’ ‘D’ ‘B’ ‘C’ ‘B’];
Abbie=[‘B’ ‘B’ ‘A’ ‘C’ ‘C’ ‘B’ ‘D’ ‘A’ ‘D’ ‘B’];
Kevin=[‘B’ ‘D’ ‘A’ ‘A’ ‘D’ ‘B’ ‘D’ ‘A’ ‘C’ ‘B’];
%These are the answers five different students gave.
function [StudentScore]=CheckScore(StudentAnswers)
StudentScore=0;
for k=1:10
if StudentAnswers(k)==CorrectAnswers(k)
StudentScore=StudentScore+10;
end
end
disp(StudentScore)
end
%The above function checks if a student’s answers match the correct
%answers, which are defined in the vector "CorrectAnswers". The score
%increases by 10 for each matching answer.
When writing, I received the following error in the script file: "Line 11: Function might be unused." For reference, Line 11 is shown below:
function [StudentScore]=CheckScore(StudentAnswers)
When I go to the Command Window to call the function "CheckScore", like below, this is the result:
>> CheckScore(Oliver)
Unrecognized function or variable ‘CheckScore’.
I’m not sure why "CheckScore" is undefined, when I (think I) defined it as a for loop within the function code. I feel like there’s a very simple fix for this, but I can’t for the life of me figure it out. Any help is appreciated, and thank you for your time! function, for loop, matlab function MATLAB Answers — New Questions
Matlab migration from 2019b to 2021b
Hello Team,
Currently i am doing the model migration from 2019 to 2021.
I have noted , while generating the code the code optimization or code generated in such a way that for the goto SLblock of model or the signal used locally inside subsystem the code is not generated and also for the nested loop the code is generated proper way.
I just want to explore more , when we migrate the matlab version of the model what are all the necessary parameters needs to check both in simulink model to code generation.
Can someone help me to explore more on this migration topic.
Thank uHello Team,
Currently i am doing the model migration from 2019 to 2021.
I have noted , while generating the code the code optimization or code generated in such a way that for the goto SLblock of model or the signal used locally inside subsystem the code is not generated and also for the nested loop the code is generated proper way.
I just want to explore more , when we migrate the matlab version of the model what are all the necessary parameters needs to check both in simulink model to code generation.
Can someone help me to explore more on this migration topic.
Thank u Hello Team,
Currently i am doing the model migration from 2019 to 2021.
I have noted , while generating the code the code optimization or code generated in such a way that for the goto SLblock of model or the signal used locally inside subsystem the code is not generated and also for the nested loop the code is generated proper way.
I just want to explore more , when we migrate the matlab version of the model what are all the necessary parameters needs to check both in simulink model to code generation.
Can someone help me to explore more on this migration topic.
Thank u matlab migration from 2019b to 2021b MATLAB Answers — New Questions
What is the relationship between sample time,simulation time and sample per frame of bernoulli Binary generator?
Bernoulli binary generator is a block in simulink which generate random binary signal.The Block consist of 2 fields Sample time and sample per frame? I want to know the relationship between sample time,sample per frame and simulation time?
For example if I set sample time 0.01s, sample per frame 1000 and simulation time 10000 then what is my bit rate?Bernoulli binary generator is a block in simulink which generate random binary signal.The Block consist of 2 fields Sample time and sample per frame? I want to know the relationship between sample time,sample per frame and simulation time?
For example if I set sample time 0.01s, sample per frame 1000 and simulation time 10000 then what is my bit rate? Bernoulli binary generator is a block in simulink which generate random binary signal.The Block consist of 2 fields Sample time and sample per frame? I want to know the relationship between sample time,sample per frame and simulation time?
For example if I set sample time 0.01s, sample per frame 1000 and simulation time 10000 then what is my bit rate? simulink, matlab, communication, digital signal processing MATLAB Answers — New Questions
I am having trouble with Taylor approximation to e^x at 0
function y=myexp(x,n);
%this is my first function
%y is the n-th order Taylor approximation to exp(x)
%x is a scalar; n is positive integer
y=1;
term=1;
for k=1:n %n is a scalar
term=term*x/k;
y=y+term;
end
I am taking this error.
Not enough input arguments.
Error in myexp (line 8)
for k=1:n %n is a scalar
what is wrong with that?function y=myexp(x,n);
%this is my first function
%y is the n-th order Taylor approximation to exp(x)
%x is a scalar; n is positive integer
y=1;
term=1;
for k=1:n %n is a scalar
term=term*x/k;
y=y+term;
end
I am taking this error.
Not enough input arguments.
Error in myexp (line 8)
for k=1:n %n is a scalar
what is wrong with that? function y=myexp(x,n);
%this is my first function
%y is the n-th order Taylor approximation to exp(x)
%x is a scalar; n is positive integer
y=1;
term=1;
for k=1:n %n is a scalar
term=term*x/k;
y=y+term;
end
I am taking this error.
Not enough input arguments.
Error in myexp (line 8)
for k=1:n %n is a scalar
what is wrong with that? matlab, homework MATLAB Answers — New Questions
Difference between MATLAB Web Server and MATLAB Web App Server ?
What is the difference between MATLAB Web Server and MATLAB Web App Server ??
https://ww2.mathworks.cn/matlabcentral/fileexchange/29027-web-server
https://ww2.mathworks.cn/en/products/matlab-web-app-server.html
Three Questions :
1.) I wish to setup a Web Page, for which when user clicks a button, it can send request to run a MATLAB .m program at the back end, and then transfer the output image to the web page. Which server (Web or Web App) should I choose ?
2.) Any real examples, not just guideline can be provided ??
3.) Any English Document about the two web server ??What is the difference between MATLAB Web Server and MATLAB Web App Server ??
https://ww2.mathworks.cn/matlabcentral/fileexchange/29027-web-server
https://ww2.mathworks.cn/en/products/matlab-web-app-server.html
Three Questions :
1.) I wish to setup a Web Page, for which when user clicks a button, it can send request to run a MATLAB .m program at the back end, and then transfer the output image to the web page. Which server (Web or Web App) should I choose ?
2.) Any real examples, not just guideline can be provided ??
3.) Any English Document about the two web server ?? What is the difference between MATLAB Web Server and MATLAB Web App Server ??
https://ww2.mathworks.cn/matlabcentral/fileexchange/29027-web-server
https://ww2.mathworks.cn/en/products/matlab-web-app-server.html
Three Questions :
1.) I wish to setup a Web Page, for which when user clicks a button, it can send request to run a MATLAB .m program at the back end, and then transfer the output image to the web page. Which server (Web or Web App) should I choose ?
2.) Any real examples, not just guideline can be provided ??
3.) Any English Document about the two web server ?? matlab web server MATLAB Answers — New Questions
How to Install Matlab R2019b from Intune
I have been tasked to migrate all our Matlab installation from SCCM to Intune. So I am starting with Matlab R2019b and having quite a hard time to get it working via Intune,
I’ve been using this custom install.bat file I found on reddit:
https://www.reddit.com/r/Intune/comments/1bjh28f/matlab_software_deployment_via_intune/#:~:text=We%20ended%20up%20wrapping%20the,a%20ton%20of%20small%20files.
setup.exe -inputFile C:tempmy_installer_input.txt timeout /t 60 >nul :WAITLOOP tasklist | find "MathWorksProductInstaller" >nul if not errorlevel 1 ( timeout /t 10 >nul goto :WAITLOOP )
I’ve finally been able to get it installed on my test environement but it’s missing all the installer input from the installer.ini file.
Any idea what I am doing wrong ?I have been tasked to migrate all our Matlab installation from SCCM to Intune. So I am starting with Matlab R2019b and having quite a hard time to get it working via Intune,
I’ve been using this custom install.bat file I found on reddit:
https://www.reddit.com/r/Intune/comments/1bjh28f/matlab_software_deployment_via_intune/#:~:text=We%20ended%20up%20wrapping%20the,a%20ton%20of%20small%20files.
setup.exe -inputFile C:tempmy_installer_input.txt timeout /t 60 >nul :WAITLOOP tasklist | find "MathWorksProductInstaller" >nul if not errorlevel 1 ( timeout /t 10 >nul goto :WAITLOOP )
I’ve finally been able to get it installed on my test environement but it’s missing all the installer input from the installer.ini file.
Any idea what I am doing wrong ? I have been tasked to migrate all our Matlab installation from SCCM to Intune. So I am starting with Matlab R2019b and having quite a hard time to get it working via Intune,
I’ve been using this custom install.bat file I found on reddit:
https://www.reddit.com/r/Intune/comments/1bjh28f/matlab_software_deployment_via_intune/#:~:text=We%20ended%20up%20wrapping%20the,a%20ton%20of%20small%20files.
setup.exe -inputFile C:tempmy_installer_input.txt timeout /t 60 >nul :WAITLOOP tasklist | find "MathWorksProductInstaller" >nul if not errorlevel 1 ( timeout /t 10 >nul goto :WAITLOOP )
I’ve finally been able to get it installed on my test environement but it’s missing all the installer input from the installer.ini file.
Any idea what I am doing wrong ? intune installation MATLAB Answers — New Questions
Which link contains the MATLAB Documentation in English Version ?
Which link contains the MATLAB Documentation in English Version ?Which link contains the MATLAB Documentation in English Version ? Which link contains the MATLAB Documentation in English Version ? matlab documentation MATLAB Answers — New Questions
May I ask can MTALAB code be run under Apache Server ?? If it can, can an example be shown for this ?
May I ask can MTALAB code be run at the backend of Apache Server ?? If it can, can an example showing the step of setup be shown for this ??May I ask can MTALAB code be run at the backend of Apache Server ?? If it can, can an example showing the step of setup be shown for this ?? May I ask can MTALAB code be run at the backend of Apache Server ?? If it can, can an example showing the step of setup be shown for this ?? apache server MATLAB Answers — New Questions
running Matlab batch error: ERROR: MATLAB error Exit Status: 0x00000001
running this command in both the command line and in Jenkins gives me error:
matlab -batch "addpath(fullfile(pwd,’functions’)); exit(runJenkins)"
here are some other text displayed ; these are unit tests outputs.The unit test passed, but the error still shows up.
Running mysqrt_Test
..
Done mysqrt_Test
__________
1
ERROR: MATLAB error Exit Status: 0x00000001
C:UsersODMEDAppDataLocalJenkins.jenkinsworkspaceMatlab test>exit 1
Build step ‘Execute Windows batch command’ marked build as failure
Finished: FAILURErunning this command in both the command line and in Jenkins gives me error:
matlab -batch "addpath(fullfile(pwd,’functions’)); exit(runJenkins)"
here are some other text displayed ; these are unit tests outputs.The unit test passed, but the error still shows up.
Running mysqrt_Test
..
Done mysqrt_Test
__________
1
ERROR: MATLAB error Exit Status: 0x00000001
C:UsersODMEDAppDataLocalJenkins.jenkinsworkspaceMatlab test>exit 1
Build step ‘Execute Windows batch command’ marked build as failure
Finished: FAILURE running this command in both the command line and in Jenkins gives me error:
matlab -batch "addpath(fullfile(pwd,’functions’)); exit(runJenkins)"
here are some other text displayed ; these are unit tests outputs.The unit test passed, but the error still shows up.
Running mysqrt_Test
..
Done mysqrt_Test
__________
1
ERROR: MATLAB error Exit Status: 0x00000001
C:UsersODMEDAppDataLocalJenkins.jenkinsworkspaceMatlab test>exit 1
Build step ‘Execute Windows batch command’ marked build as failure
Finished: FAILURE batch, jenkins, cmd, command line MATLAB Answers — New Questions