Tag Archives: matlab
Compute Gradients over FE mesh using Nodal Solution
I have computed the solution to an electrostatics problem using the finite element method in a slightly non-standard workflow (I could not figure out how to accomplish this within the PDE modeling environment, see here):
Define finite element mesh outside the PDE modeling environment
Create an electrostatics model and import the mesh
Use FEM = assembleFEMatrices(model) to assemble the global stiffness matrix
Manually prescribe Dirichlet boundary conditions at mesh nodes by constructing an H matrix (not sure what the technical term here is – a condensation operator, a boundary condition applicator, a row eliminator?) and using the pdenullorth(H). By the way – it’s strange that this function does not have any documentation that I can find!
Solve the FE problem using a backslash operation. Here’s steps 3-5 (tetMesh struct contains the tetrahedral mesh I’ve imported, and catNodes & anNodes identify the nodes where I’d like to prescribe voltage boundary conditions):
%assemble matrices (right now F is always zero)
FEM = assembleFEMatrices(model,"KF");
%create a vector of prescribed voltages
Vd = sparse(tetMesh.nNodes,1);
Vd(tetMesh.catNodes) = 1000;
Vd(tetMesh.anNodes) = 0;
%form the consdensing matrix
H = sparse(1:tetMesh.nDirichlet,[tetMesh.catNodes tetMesh.anNodes],…
ones(tetMesh.nDirichlet,1),tetMesh.nDirichlet,tetMesh.nNodes);
[B,~] = pdenullorth(H);
% form the reduced matrix algebra problem
Kc = B’*FEM.K*B;
Fc = B’*(FEM.F-(FEM.K*Vd));
%compute the FE solution
u = B*(KcFc) + Vd;
This works fine – I can now plot the nodal solutions (the electric potential) over the problem domain:
Now, I would like to compute the derived quantities associated with normal electrostatics solutions – namely the Electric Field, which is simply the gradient of the Electric Potential Field.
Ordinarily result = solvepde(model) would compute this quantity automatically – but I computed my solution simply using . Is there a way to perform this using the FE mesh that the problem was solved on? I have a hunch that the shape functions and their derivatives embedded in the FE mesh will produce a more accurate gradient field than if I project the solution to a uniform grid, compute a gradient, and project back. For this reason I would like to avoid using scatteredInterpolant().I have computed the solution to an electrostatics problem using the finite element method in a slightly non-standard workflow (I could not figure out how to accomplish this within the PDE modeling environment, see here):
Define finite element mesh outside the PDE modeling environment
Create an electrostatics model and import the mesh
Use FEM = assembleFEMatrices(model) to assemble the global stiffness matrix
Manually prescribe Dirichlet boundary conditions at mesh nodes by constructing an H matrix (not sure what the technical term here is – a condensation operator, a boundary condition applicator, a row eliminator?) and using the pdenullorth(H). By the way – it’s strange that this function does not have any documentation that I can find!
Solve the FE problem using a backslash operation. Here’s steps 3-5 (tetMesh struct contains the tetrahedral mesh I’ve imported, and catNodes & anNodes identify the nodes where I’d like to prescribe voltage boundary conditions):
%assemble matrices (right now F is always zero)
FEM = assembleFEMatrices(model,"KF");
%create a vector of prescribed voltages
Vd = sparse(tetMesh.nNodes,1);
Vd(tetMesh.catNodes) = 1000;
Vd(tetMesh.anNodes) = 0;
%form the consdensing matrix
H = sparse(1:tetMesh.nDirichlet,[tetMesh.catNodes tetMesh.anNodes],…
ones(tetMesh.nDirichlet,1),tetMesh.nDirichlet,tetMesh.nNodes);
[B,~] = pdenullorth(H);
% form the reduced matrix algebra problem
Kc = B’*FEM.K*B;
Fc = B’*(FEM.F-(FEM.K*Vd));
%compute the FE solution
u = B*(KcFc) + Vd;
This works fine – I can now plot the nodal solutions (the electric potential) over the problem domain:
Now, I would like to compute the derived quantities associated with normal electrostatics solutions – namely the Electric Field, which is simply the gradient of the Electric Potential Field.
Ordinarily result = solvepde(model) would compute this quantity automatically – but I computed my solution simply using . Is there a way to perform this using the FE mesh that the problem was solved on? I have a hunch that the shape functions and their derivatives embedded in the FE mesh will produce a more accurate gradient field than if I project the solution to a uniform grid, compute a gradient, and project back. For this reason I would like to avoid using scatteredInterpolant(). I have computed the solution to an electrostatics problem using the finite element method in a slightly non-standard workflow (I could not figure out how to accomplish this within the PDE modeling environment, see here):
Define finite element mesh outside the PDE modeling environment
Create an electrostatics model and import the mesh
Use FEM = assembleFEMatrices(model) to assemble the global stiffness matrix
Manually prescribe Dirichlet boundary conditions at mesh nodes by constructing an H matrix (not sure what the technical term here is – a condensation operator, a boundary condition applicator, a row eliminator?) and using the pdenullorth(H). By the way – it’s strange that this function does not have any documentation that I can find!
Solve the FE problem using a backslash operation. Here’s steps 3-5 (tetMesh struct contains the tetrahedral mesh I’ve imported, and catNodes & anNodes identify the nodes where I’d like to prescribe voltage boundary conditions):
%assemble matrices (right now F is always zero)
FEM = assembleFEMatrices(model,"KF");
%create a vector of prescribed voltages
Vd = sparse(tetMesh.nNodes,1);
Vd(tetMesh.catNodes) = 1000;
Vd(tetMesh.anNodes) = 0;
%form the consdensing matrix
H = sparse(1:tetMesh.nDirichlet,[tetMesh.catNodes tetMesh.anNodes],…
ones(tetMesh.nDirichlet,1),tetMesh.nDirichlet,tetMesh.nNodes);
[B,~] = pdenullorth(H);
% form the reduced matrix algebra problem
Kc = B’*FEM.K*B;
Fc = B’*(FEM.F-(FEM.K*Vd));
%compute the FE solution
u = B*(KcFc) + Vd;
This works fine – I can now plot the nodal solutions (the electric potential) over the problem domain:
Now, I would like to compute the derived quantities associated with normal electrostatics solutions – namely the Electric Field, which is simply the gradient of the Electric Potential Field.
Ordinarily result = solvepde(model) would compute this quantity automatically – but I computed my solution simply using . Is there a way to perform this using the FE mesh that the problem was solved on? I have a hunch that the shape functions and their derivatives embedded in the FE mesh will produce a more accurate gradient field than if I project the solution to a uniform grid, compute a gradient, and project back. For this reason I would like to avoid using scatteredInterpolant(). partial differential equations, gradient, electric field, finite element mesh, post-process, pde modeling MATLAB Answers — New Questions
how to replace elements in top third, middle third, and bottom third of matix
This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.
My task is the following:
Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:
M = trio(2,4)
M =
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.
function T = trio (n, m)
T = randi (10, (3 * n) , m);
T ( 1:n , 🙂 = 1;
T ( (n+1):(end-(n-1)) , 🙂 = 2;
T ( (n+3):end, 🙂 = 3;
end
How is it possible to call out only top third, middle third, and bottom third of any matrix?
Thank you in advance.This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.
My task is the following:
Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:
M = trio(2,4)
M =
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.
function T = trio (n, m)
T = randi (10, (3 * n) , m);
T ( 1:n , 🙂 = 1;
T ( (n+1):(end-(n-1)) , 🙂 = 2;
T ( (n+3):end, 🙂 = 3;
end
How is it possible to call out only top third, middle third, and bottom third of any matrix?
Thank you in advance. This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.
My task is the following:
Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:
M = trio(2,4)
M =
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.
function T = trio (n, m)
T = randi (10, (3 * n) , m);
T ( 1:n , 🙂 = 1;
T ( (n+1):(end-(n-1)) , 🙂 = 2;
T ( (n+3):end, 🙂 = 3;
end
How is it possible to call out only top third, middle third, and bottom third of any matrix?
Thank you in advance. matrix manipulation, homework, soft-lock MATLAB Answers — New Questions
rosgenmsg(folderpath) from custom ros msgs add on causes Index exceeds the number of array elements (0).
Hello,
I’m trying to get Matlab to be able to use some custom ROS msgs from a ROS package that follows the required structure has worked in other environments. I’ve followed the instructions at https://www.mathworks.com/help/ros/ug/create-custom-messages-from-ros-package.html but will get a ‘Index exceeds the number of array elements (0).’ Error on the rosgenmsg(folderpath)
Any one run into this issue before or is this a bug.Hello,
I’m trying to get Matlab to be able to use some custom ROS msgs from a ROS package that follows the required structure has worked in other environments. I’ve followed the instructions at https://www.mathworks.com/help/ros/ug/create-custom-messages-from-ros-package.html but will get a ‘Index exceeds the number of array elements (0).’ Error on the rosgenmsg(folderpath)
Any one run into this issue before or is this a bug. Hello,
I’m trying to get Matlab to be able to use some custom ROS msgs from a ROS package that follows the required structure has worked in other environments. I’ve followed the instructions at https://www.mathworks.com/help/ros/ug/create-custom-messages-from-ros-package.html but will get a ‘Index exceeds the number of array elements (0).’ Error on the rosgenmsg(folderpath)
Any one run into this issue before or is this a bug. ros, custom messages, rosgenmsg MATLAB Answers — New Questions
PV MPPT FLC using Boost DC-DC Converter
I am simulating a solar panel system using MPPT FLC. I want to ask why most of the models I refer to on the internet use a 20 ohm load for this method.
In reality, when I try to change to any other arbitrary load, the simulation graph shows very strong oscillations and is not optimal.
And the optimal load for a 213.15W panel is 3.95 ohms, from what I know.I am simulating a solar panel system using MPPT FLC. I want to ask why most of the models I refer to on the internet use a 20 ohm load for this method.
In reality, when I try to change to any other arbitrary load, the simulation graph shows very strong oscillations and is not optimal.
And the optimal load for a 213.15W panel is 3.95 ohms, from what I know. I am simulating a solar panel system using MPPT FLC. I want to ask why most of the models I refer to on the internet use a 20 ohm load for this method.
In reality, when I try to change to any other arbitrary load, the simulation graph shows very strong oscillations and is not optimal.
And the optimal load for a 213.15W panel is 3.95 ohms, from what I know. pv mppt flc using boost dc-dc converter MATLAB Answers — New Questions
Describe the solution trajectory of differential systems with mixed time-varying delay
Hi everyone, please help me write the matlab code to describe the solution trajectory for the class differential systems with mixed time-varying delay as follows
Thank you very much!Hi everyone, please help me write the matlab code to describe the solution trajectory for the class differential systems with mixed time-varying delay as follows
Thank you very much! Hi everyone, please help me write the matlab code to describe the solution trajectory for the class differential systems with mixed time-varying delay as follows
Thank you very much! oed MATLAB Answers — New Questions
Power Spectral Density of a bipolar digital signal
I am having a difficult time trying to plot the power spectral density of a bipolar digital signal with random values, based on an array. For example:
signal=[0 -1 1 0 1 -1];
Then I create a time vector based on a transfer rate of a specified value like this:
D=160000 % rate transfer of 160Kbps
t=[0:1/D:length(signal)/D];
And I plot the signal like this:
stairs(t,signal);
My signal looks like this :
My question is what should I do to be able to represent the power spectral density of such a signal? Is there a more direct way in Matlab than it would be by implementing all kinds of formulas? In theory, my plot should look roughly like this:
Thanks in advance!I am having a difficult time trying to plot the power spectral density of a bipolar digital signal with random values, based on an array. For example:
signal=[0 -1 1 0 1 -1];
Then I create a time vector based on a transfer rate of a specified value like this:
D=160000 % rate transfer of 160Kbps
t=[0:1/D:length(signal)/D];
And I plot the signal like this:
stairs(t,signal);
My signal looks like this :
My question is what should I do to be able to represent the power spectral density of such a signal? Is there a more direct way in Matlab than it would be by implementing all kinds of formulas? In theory, my plot should look roughly like this:
Thanks in advance! I am having a difficult time trying to plot the power spectral density of a bipolar digital signal with random values, based on an array. For example:
signal=[0 -1 1 0 1 -1];
Then I create a time vector based on a transfer rate of a specified value like this:
D=160000 % rate transfer of 160Kbps
t=[0:1/D:length(signal)/D];
And I plot the signal like this:
stairs(t,signal);
My signal looks like this :
My question is what should I do to be able to represent the power spectral density of such a signal? Is there a more direct way in Matlab than it would be by implementing all kinds of formulas? In theory, my plot should look roughly like this:
Thanks in advance! psd, power spectral density, digital signal, array based signal MATLAB Answers — New Questions
Error: Conversion to logical from sym is not possible
Hello there. I get the following error for my code: "Conversion to logical from sym is not possible".
I need the if statement due to the root in my equation: if my d gets negativ, it can’t solve the equation anymore. that is why i would like to have the following condition that in case of a negativ number it will put d equal to zero.
How can I include if statements in a solver (so having values that are saved as syms)? I need the solver function because the real equation is way more complex but having a root.
Also how can I export the solution to a excel file? I don’t understand as the solution is still saved as sym. is there the possibility to convert a sym to a double in the end of the code?
syms x
a = 30
b = 20
c = 10
if d > 0
d = (x-c).*2
else d = 0
end
eqn = a + b – 200.*x – d^0.5 == 0
sol_x = vpasolve(eqn, x)Hello there. I get the following error for my code: "Conversion to logical from sym is not possible".
I need the if statement due to the root in my equation: if my d gets negativ, it can’t solve the equation anymore. that is why i would like to have the following condition that in case of a negativ number it will put d equal to zero.
How can I include if statements in a solver (so having values that are saved as syms)? I need the solver function because the real equation is way more complex but having a root.
Also how can I export the solution to a excel file? I don’t understand as the solution is still saved as sym. is there the possibility to convert a sym to a double in the end of the code?
syms x
a = 30
b = 20
c = 10
if d > 0
d = (x-c).*2
else d = 0
end
eqn = a + b – 200.*x – d^0.5 == 0
sol_x = vpasolve(eqn, x) Hello there. I get the following error for my code: "Conversion to logical from sym is not possible".
I need the if statement due to the root in my equation: if my d gets negativ, it can’t solve the equation anymore. that is why i would like to have the following condition that in case of a negativ number it will put d equal to zero.
How can I include if statements in a solver (so having values that are saved as syms)? I need the solver function because the real equation is way more complex but having a root.
Also how can I export the solution to a excel file? I don’t understand as the solution is still saved as sym. is there the possibility to convert a sym to a double in the end of the code?
syms x
a = 30
b = 20
c = 10
if d > 0
d = (x-c).*2
else d = 0
end
eqn = a + b – 200.*x – d^0.5 == 0
sol_x = vpasolve(eqn, x) sym MATLAB Answers — New Questions
How to apply attention mechanism to object detection in RGB images
Hello, as this is my first time using MATLAB for research in deep learning, I am not very proficient yet. Can someone give me an example of how to apply attention mechanisms such as attention layers and self-attention layers to object detection in RGB images? Thank you very much.Hello, as this is my first time using MATLAB for research in deep learning, I am not very proficient yet. Can someone give me an example of how to apply attention mechanisms such as attention layers and self-attention layers to object detection in RGB images? Thank you very much. Hello, as this is my first time using MATLAB for research in deep learning, I am not very proficient yet. Can someone give me an example of how to apply attention mechanisms such as attention layers and self-attention layers to object detection in RGB images? Thank you very much. deep learning, attention mechanism, rgb image MATLAB Answers — New Questions
Problem in “Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function”, Task 1, MatLab Fundamentals
I am currently finishing the course "MatLab Fundamentals" but I cannot reach 100% because in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 1, I’m not able to answer in the correct way to that Task. Since I thought I answered right, I checked the solution and it was the same as my script; however even copying and pasting the solution script and trying to submit the Task, it appears to be "Incorrect" (Is pp calculated from the function paretoperc?). I can’t understand if I’m missing something or if there’s some kind of problem since also the solution script doesn’t work. What can I do?
Here’s the code:
Task 1
pp = paretoperc(medals)
Task 2
Further Practice
function pp = paretoperc(x)
% Cumulative contribution of data points (in order)
cc = cumsum(sort(x(:),"descend")); % (:) to ensure column vector
cc = 100*cc/cc(end); % Normalize to percentage
% Corresponding percentiles (column vector to match cc)
pct = (1:numel(x))’;
pct = 100*pct/numel(pct); % Normalize to percentage
% Find the number of data values needed so that
% P% of the data is in (100-P)% of the values
idx = find(cc >= (100-pct),1,"first");
pp = cc(idx);
endI am currently finishing the course "MatLab Fundamentals" but I cannot reach 100% because in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 1, I’m not able to answer in the correct way to that Task. Since I thought I answered right, I checked the solution and it was the same as my script; however even copying and pasting the solution script and trying to submit the Task, it appears to be "Incorrect" (Is pp calculated from the function paretoperc?). I can’t understand if I’m missing something or if there’s some kind of problem since also the solution script doesn’t work. What can I do?
Here’s the code:
Task 1
pp = paretoperc(medals)
Task 2
Further Practice
function pp = paretoperc(x)
% Cumulative contribution of data points (in order)
cc = cumsum(sort(x(:),"descend")); % (:) to ensure column vector
cc = 100*cc/cc(end); % Normalize to percentage
% Corresponding percentiles (column vector to match cc)
pct = (1:numel(x))’;
pct = 100*pct/numel(pct); % Normalize to percentage
% Find the number of data values needed so that
% P% of the data is in (100-P)% of the values
idx = find(cc >= (100-pct),1,"first");
pp = cc(idx);
end I am currently finishing the course "MatLab Fundamentals" but I cannot reach 100% because in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 1, I’m not able to answer in the correct way to that Task. Since I thought I answered right, I checked the solution and it was the same as my script; however even copying and pasting the solution script and trying to submit the Task, it appears to be "Incorrect" (Is pp calculated from the function paretoperc?). I can’t understand if I’m missing something or if there’s some kind of problem since also the solution script doesn’t work. What can I do?
Here’s the code:
Task 1
pp = paretoperc(medals)
Task 2
Further Practice
function pp = paretoperc(x)
% Cumulative contribution of data points (in order)
cc = cumsum(sort(x(:),"descend")); % (:) to ensure column vector
cc = 100*cc/cc(end); % Normalize to percentage
% Corresponding percentiles (column vector to match cc)
pct = (1:numel(x))’;
pct = 100*pct/numel(pct); % Normalize to percentage
% Find the number of data values needed so that
% P% of the data is in (100-P)% of the values
idx = find(cc >= (100-pct),1,"first");
pp = cc(idx);
end local function MATLAB Answers — New Questions
what is .data extension in matlab
Hi,
I have the code below:
X=importdata(‘test.csv’);
B = X.data;
I searched for the .data extenion file type , but could not find explaination in matlab !!
please could you explain what is this file type and when i can use it!!!
why not use csv read ? instead of importdata() !!!
ThanksHi,
I have the code below:
X=importdata(‘test.csv’);
B = X.data;
I searched for the .data extenion file type , but could not find explaination in matlab !!
please could you explain what is this file type and when i can use it!!!
why not use csv read ? instead of importdata() !!!
Thanks Hi,
I have the code below:
X=importdata(‘test.csv’);
B = X.data;
I searched for the .data extenion file type , but could not find explaination in matlab !!
please could you explain what is this file type and when i can use it!!!
why not use csv read ? instead of importdata() !!!
Thanks file type, matlab MATLAB Answers — New Questions
MatLab won’t let me publish to PDF.
When I try to publish to a pdf, MatLab responds with:
Warning: File not found or permission denied
> In publish
In publish
In onCleanup/delete (line 25)
In publish
In publish
Loading remote resource not allowed. Remote resource: http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtdWhen I try to publish to a pdf, MatLab responds with:
Warning: File not found or permission denied
> In publish
In publish
In onCleanup/delete (line 25)
In publish
In publish
Loading remote resource not allowed. Remote resource: http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd When I try to publish to a pdf, MatLab responds with:
Warning: File not found or permission denied
> In publish
In publish
In onCleanup/delete (line 25)
In publish
In publish
Loading remote resource not allowed. Remote resource: http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd pdf, publish MATLAB Answers — New Questions
I want all possible distinct lists of the pairs of the elements that can be made from a vector having j ones, j twos, and j threes where j is an even integer.
I have a list L of integers comprising j ones, j twos, and j threes, where j is an even integer. For example, if j=4, then the list could be L= [1 1 1 1 2 2 2 2 3 3 3 3] of length 3*j=12. I want to make distinct lists PLi, i = 1,2,….m (i and m are integers) showing various ways to pair the elements of L, using each element from L once and only once. Since there are 3*j elements in L, each PLi will have 3*j/2 pairs. The question is how many distinct lists PLi can be made if the order of the two elements in a pair is immaterial and if the order in which the pairs are listed in each PLi is immaterial. For example, one pair list, call it PL1, could be PL1 = [ [1,1]; [1,1]; [2,3]; [2,2]; [2,3]; [3,3] ] where the pairs are separated by semi-colons. The pair list [ [2,2]; [1,1]; [1,1]; [3,2]; [3,2]; [3,3] ] would not be distinct from PL1, but the pair list PL2=[ [1,1]; [1,2]; [1,3]; [2,2]; [2,3]; [3,3] ] would be distinct.
Is there a MatLab routine/command which, given L, returns all possible distinct lists of 3*j/2 pairs made from L? If not, is there an efficient algorithm to calculate all possible distinct lists PLi for large j or to estimate the dependence of the number of distinct lists (m) on the value of j?
Such a routine/command might be regarded as in the same class as nchoosek(L,2). ?I have a list L of integers comprising j ones, j twos, and j threes, where j is an even integer. For example, if j=4, then the list could be L= [1 1 1 1 2 2 2 2 3 3 3 3] of length 3*j=12. I want to make distinct lists PLi, i = 1,2,….m (i and m are integers) showing various ways to pair the elements of L, using each element from L once and only once. Since there are 3*j elements in L, each PLi will have 3*j/2 pairs. The question is how many distinct lists PLi can be made if the order of the two elements in a pair is immaterial and if the order in which the pairs are listed in each PLi is immaterial. For example, one pair list, call it PL1, could be PL1 = [ [1,1]; [1,1]; [2,3]; [2,2]; [2,3]; [3,3] ] where the pairs are separated by semi-colons. The pair list [ [2,2]; [1,1]; [1,1]; [3,2]; [3,2]; [3,3] ] would not be distinct from PL1, but the pair list PL2=[ [1,1]; [1,2]; [1,3]; [2,2]; [2,3]; [3,3] ] would be distinct.
Is there a MatLab routine/command which, given L, returns all possible distinct lists of 3*j/2 pairs made from L? If not, is there an efficient algorithm to calculate all possible distinct lists PLi for large j or to estimate the dependence of the number of distinct lists (m) on the value of j?
Such a routine/command might be regarded as in the same class as nchoosek(L,2). ? I have a list L of integers comprising j ones, j twos, and j threes, where j is an even integer. For example, if j=4, then the list could be L= [1 1 1 1 2 2 2 2 3 3 3 3] of length 3*j=12. I want to make distinct lists PLi, i = 1,2,….m (i and m are integers) showing various ways to pair the elements of L, using each element from L once and only once. Since there are 3*j elements in L, each PLi will have 3*j/2 pairs. The question is how many distinct lists PLi can be made if the order of the two elements in a pair is immaterial and if the order in which the pairs are listed in each PLi is immaterial. For example, one pair list, call it PL1, could be PL1 = [ [1,1]; [1,1]; [2,3]; [2,2]; [2,3]; [3,3] ] where the pairs are separated by semi-colons. The pair list [ [2,2]; [1,1]; [1,1]; [3,2]; [3,2]; [3,3] ] would not be distinct from PL1, but the pair list PL2=[ [1,1]; [1,2]; [1,3]; [2,2]; [2,3]; [3,3] ] would be distinct.
Is there a MatLab routine/command which, given L, returns all possible distinct lists of 3*j/2 pairs made from L? If not, is there an efficient algorithm to calculate all possible distinct lists PLi for large j or to estimate the dependence of the number of distinct lists (m) on the value of j?
Such a routine/command might be regarded as in the same class as nchoosek(L,2). ? matlab function, mathematics, code generation MATLAB Answers — New Questions
How can I step up three phase voltage using three phase transformer in MATALB Simulink.
Hello everyone,
I am working on a model in MATLAB where I need to step up a 20 kV three-phase voltage to 200 kV. I used the three-phase transformer from the Simulink library and set the parameters to 20 kV on the primary side and 200 kV on the secondary side. However, when I run the simulation, I do not achieve the desired 200 kV output. Can someone please suggest how I can fix this issue? Additionally, if there are any resources or references that could help me with my query, I would appreciate it.Thank you!Hello everyone,
I am working on a model in MATLAB where I need to step up a 20 kV three-phase voltage to 200 kV. I used the three-phase transformer from the Simulink library and set the parameters to 20 kV on the primary side and 200 kV on the secondary side. However, when I run the simulation, I do not achieve the desired 200 kV output. Can someone please suggest how I can fix this issue? Additionally, if there are any resources or references that could help me with my query, I would appreciate it.Thank you! Hello everyone,
I am working on a model in MATLAB where I need to step up a 20 kV three-phase voltage to 200 kV. I used the three-phase transformer from the Simulink library and set the parameters to 20 kV on the primary side and 200 kV on the secondary side. However, when I run the simulation, I do not achieve the desired 200 kV output. Can someone please suggest how I can fix this issue? Additionally, if there are any resources or references that could help me with my query, I would appreciate it.Thank you! three phase transformere MATLAB Answers — New Questions
Why do I get “Encountered complex value when computing gradient…” error in my custom network training
I’m training a network with a custom loss fuction, but I got this error when traning the network:
Error using dlarray/dlgradient
Encountered complex value when computing gradient with respect to an output of fullyconnect. Convert all outputs of fullyconnect to real.
The following is my modelloss function:
function [loss,gradients] = modelLoss(net,X,A)
[Nt,Ng] = size(A);
[~,~,miniBatchSize] = size(X);
[Y1,Y2] = forward(net,X); % the network output
Nrf = size(Y1,1)/2;
% convert real value outputs to complex valued vector & matrices : f1, F2
f1_split = reshape(Y1,[Nrf,2,miniBatchSize]);
f1 = squeeze(complex(f1_split(:,1,:),f1_split(:,2,:)));
F2_phase = reshape(Y2,[Nt,Nrf,miniBatchSize]);
F2 = exp(1i*F2_phase)/sqrt(Nt);
% Compute loss.
loss = dlarray(0);
for batch = 1:miniBatchSize % calculate the loss (as temp_loss) in every batch
f = F2(:,:,batch)*f1(:,batch); % f is a complex valued vector
temp_loss = sqrt(sum( ( abs(A’*f).^2-X(:,:,batch) ).^2 )); % temp_loss sould always be real
% A above is a complex matrices of size Ng*Nt
% X is real valued vector of size Ng*1
loss = loss + temp_loss;
end
loss = loss/(miniBatchSize*Ng);
% Compute gradients.
gradients = dlgradient(loss,net.Learnables);
end
And update loss and calculating gradients using dlfeval() as usual.
[loss,gradients] = dlfeval(@modelLoss,net,X,A);
I think I made the traced loss in every calculation as real valued.
Please help me find out where the problem is, thanks!I’m training a network with a custom loss fuction, but I got this error when traning the network:
Error using dlarray/dlgradient
Encountered complex value when computing gradient with respect to an output of fullyconnect. Convert all outputs of fullyconnect to real.
The following is my modelloss function:
function [loss,gradients] = modelLoss(net,X,A)
[Nt,Ng] = size(A);
[~,~,miniBatchSize] = size(X);
[Y1,Y2] = forward(net,X); % the network output
Nrf = size(Y1,1)/2;
% convert real value outputs to complex valued vector & matrices : f1, F2
f1_split = reshape(Y1,[Nrf,2,miniBatchSize]);
f1 = squeeze(complex(f1_split(:,1,:),f1_split(:,2,:)));
F2_phase = reshape(Y2,[Nt,Nrf,miniBatchSize]);
F2 = exp(1i*F2_phase)/sqrt(Nt);
% Compute loss.
loss = dlarray(0);
for batch = 1:miniBatchSize % calculate the loss (as temp_loss) in every batch
f = F2(:,:,batch)*f1(:,batch); % f is a complex valued vector
temp_loss = sqrt(sum( ( abs(A’*f).^2-X(:,:,batch) ).^2 )); % temp_loss sould always be real
% A above is a complex matrices of size Ng*Nt
% X is real valued vector of size Ng*1
loss = loss + temp_loss;
end
loss = loss/(miniBatchSize*Ng);
% Compute gradients.
gradients = dlgradient(loss,net.Learnables);
end
And update loss and calculating gradients using dlfeval() as usual.
[loss,gradients] = dlfeval(@modelLoss,net,X,A);
I think I made the traced loss in every calculation as real valued.
Please help me find out where the problem is, thanks! I’m training a network with a custom loss fuction, but I got this error when traning the network:
Error using dlarray/dlgradient
Encountered complex value when computing gradient with respect to an output of fullyconnect. Convert all outputs of fullyconnect to real.
The following is my modelloss function:
function [loss,gradients] = modelLoss(net,X,A)
[Nt,Ng] = size(A);
[~,~,miniBatchSize] = size(X);
[Y1,Y2] = forward(net,X); % the network output
Nrf = size(Y1,1)/2;
% convert real value outputs to complex valued vector & matrices : f1, F2
f1_split = reshape(Y1,[Nrf,2,miniBatchSize]);
f1 = squeeze(complex(f1_split(:,1,:),f1_split(:,2,:)));
F2_phase = reshape(Y2,[Nt,Nrf,miniBatchSize]);
F2 = exp(1i*F2_phase)/sqrt(Nt);
% Compute loss.
loss = dlarray(0);
for batch = 1:miniBatchSize % calculate the loss (as temp_loss) in every batch
f = F2(:,:,batch)*f1(:,batch); % f is a complex valued vector
temp_loss = sqrt(sum( ( abs(A’*f).^2-X(:,:,batch) ).^2 )); % temp_loss sould always be real
% A above is a complex matrices of size Ng*Nt
% X is real valued vector of size Ng*1
loss = loss + temp_loss;
end
loss = loss/(miniBatchSize*Ng);
% Compute gradients.
gradients = dlgradient(loss,net.Learnables);
end
And update loss and calculating gradients using dlfeval() as usual.
[loss,gradients] = dlfeval(@modelLoss,net,X,A);
I think I made the traced loss in every calculation as real valued.
Please help me find out where the problem is, thanks! dlgradient, complex value when computing gradient MATLAB Answers — New Questions
Shapefile or KML from 2d Matrix
I created a two-dimensional matrix (720, 1440) of global temperatures based on 0.5 degree latitude/longitude. I’d like to make a projected shapefile or kml from this that I can import into ArcPro or similar GIS platform. I have the mapping toolbox and access to shapewrite but I’m not exactly sure how to accomplish the task.
Any idea would be greatly appreciated.I created a two-dimensional matrix (720, 1440) of global temperatures based on 0.5 degree latitude/longitude. I’d like to make a projected shapefile or kml from this that I can import into ArcPro or similar GIS platform. I have the mapping toolbox and access to shapewrite but I’m not exactly sure how to accomplish the task.
Any idea would be greatly appreciated. I created a two-dimensional matrix (720, 1440) of global temperatures based on 0.5 degree latitude/longitude. I’d like to make a projected shapefile or kml from this that I can import into ArcPro or similar GIS platform. I have the mapping toolbox and access to shapewrite but I’m not exactly sure how to accomplish the task.
Any idea would be greatly appreciated. shapefile, kml, shapewrite, matrix, gis MATLAB Answers — New Questions
“double” vs. “uint8” input using “imshow” function
When using the command, "imshow(image)", I get an error when "image" has type "double". If I convert "image" to type "uint8", then "imshow" produces the image. Why is there an error with type "double"?When using the command, "imshow(image)", I get an error when "image" has type "double". If I convert "image" to type "uint8", then "imshow" produces the image. Why is there an error with type "double"? When using the command, "imshow(image)", I get an error when "image" has type "double". If I convert "image" to type "uint8", then "imshow" produces the image. Why is there an error with type "double"? double MATLAB Answers — New Questions
Curve Fitting for a Rational Polynomial Model.
Dear all,
I want to find the best rational Polynomial model that can fit the data shown.
any help would be appreciated.
Data are in dB.Dear all,
I want to find the best rational Polynomial model that can fit the data shown.
any help would be appreciated.
Data are in dB. Dear all,
I want to find the best rational Polynomial model that can fit the data shown.
any help would be appreciated.
Data are in dB. curve fitting MATLAB Answers — New Questions