Currently, I'm working on a school project involving buck converters. As current increase through an inductor, its inductance decrease (most likely). Each phase is adding an inductor. By adding an inductor, I divide the current by each added inductor. The current is ramped from 0 to 500.
My issue with the following code is that it does not use each array value of i_L(i,j) correctly. I receive some negative values, which is absolutely wrong.
In example...
At 500 Amps with 10 phases, each inductor uses 50 amps. Now L will be designed after
i_L(i,j)=current(j)./phases(i)= 500/10=50amps
L(i,j)= (-9.22297516731983*10^(-16).*(50^(4)))+(9.96260934359008*10^(-14).*(50^(3)))-(3.6355216850551*10^(-12).*(50^(2)))+(9.0205832462444*10^(-12).*(50^(1)))+1.06054781561763E-07 = 1.04106*10^(-7)
and so on
creating 10x10 = 100 cells
clc; clear all;
phases=linspace(1,10,10);
current=linspace(0,500,10);
for j = 1:10
for i=1:10
i_L(i,j)=current(j)./phases(i);
L(i,j)=(-0.000000000000000922297516731983*(i_L(i,j).^(4)))+(0.000000000000099626093435900800*(i_L(i,j).^(3)))-(0.000000000003635521685055100000*(i_L(i,j).^(2)))+(0.000000000009020583246244400000*(i_L(i,j).^(1)))+0.000000106054781561763000000000;
end
end
Thank you!
Your matrix i_L(i,j) got values up to 500=500(current)/1(amp).
The polynomial you're using is generating negative solutions for values greater than 130.
So the operation is using each array value correct.
Maybe you should reevaluate the polynomial, if you're dissatisfied with the solution.
Try:
x=[0:1:500];
y=(-9.22297516731983*10^(-16).*(x.^(4)))+(9.96260934359008*10^(-14).*(x.^(3)))-(3.6355216850551*10^(-12).*(x.^(2)))+(9.0205832462444*10^(-12).*(x.^(1)))+1.06054781561763E-07;
plot(x,y)
You will see the polynomial will diverge against negative infinite for positive values.
I am trying to implement Hough transform in Matlab to find circles in a picture.
In the accumulator matrix, the global maximum is 105 at A(32,31,24). So I'm able to get this: max circle
The problem is, how can i find the local maxima to find the rest of the circles?
I wrote this to find A(i,j,k) which is bigger than the 26 adjacent points (26-Connected voxel neighborhood):
[i j k]=find(A~=0) ;
f=0;
for s=1:size(i)
if(i(s)~=100&&j(s)~=100&&k(s)~=141&&i(s)~=1&&j(s)~=1&&k(s)~=1)
if (A(i(s),j(s),k(s))>A(i(s)-1,j(s),k(s))&&A(i(s),j(s),k(s))>A(i(s)+1,j(s),k(s))&&A(i(s),j(s),k(s))>A(i(s),j(s)-1,k(s))&&A(i(s),j(s),k(s))>A(i(s),j(s)+1,k(s))&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)-1,k(s))&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)+1,k(s))&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)+1,k(s))&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)-1,k(s))&&A(i(s),j(s),k(s))>A(i(s),j(s),k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s),k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s),k(s)+1)&&A(i(s),j(s),k(s))>A(i(s),j(s)-1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s),j(s)+1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)-1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)+1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)+1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)-1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s),j(s),k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s),k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s),k(s)-1)&&A(i(s),j(s),k(s))>A(i(s),j(s)-1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s),j(s)+1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)-1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)+1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)+1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)-1,k(s)-1))
f=f+1
i(s)
j(s)
k(s)
end
end
end
Why i never got these correct i,j,k and f is always 0? I think i should at least find (32,31,24) and f=1?
Can anyone help me ?
Thank you so much!
The complete code is here:
im=imread('C:\Users\dell\Desktop\tp-complet\Hough\four.png');
sigma = 0.3;
gausFilter = fspecial('gaussian',[5 5],sigma);
sobelFilter=fspecial('sobel');
img=imfilter(im,gausFilter,'replicate');
ims=edge(img,'sobel');
rmax=size(im,1);
cmax=size(im,2);
radmax=round(sqrt(rmax^2+cmax^2));
for i=1:rmax
for j=1:cmax
for k=1:radmax
A(i,j,k)=0;
end
end
end
[r c]=find(ims==1);
length=size(r);
for k=1:length
for l=1:rmax
for m=1:cmax
if((l~=r(k))&&(m~=c(k)))
x=sqrt((l-r(k))^2+(m-c(k))^2);
x=round(x);
A(l,m,x)=A(l,m,x)+1;
end
end
end
end
[i j k]=find(A~=0) ;
f=0;
for s=1:size(i)
if(i(s)~=100&&j(s)~=100&&k(s)~=141&&i(s)~=1&&j(s)~=1&&k(s)~=1)
if (A(i(s),j(s),k(s))>A(i(s)-1,j(s),k(s))&&A(i(s),j(s),k(s))>A(i(s)+1,j(s),k(s))&&A(i(s),j(s),k(s))>A(i(s),j(s)-1,k(s))&&A(i(s),j(s),k(s))>A(i(s),j(s)+1,k(s))&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)-1,k(s))&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)+1,k(s))&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)+1,k(s))&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)-1,k(s))&&A(i(s),j(s),k(s))>A(i(s),j(s),k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s),k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s),k(s)+1)&&A(i(s),j(s),k(s))>A(i(s),j(s)-1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s),j(s)+1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)-1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)+1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)+1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)-1,k(s)+1)&&A(i(s),j(s),k(s))>A(i(s),j(s),k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s),k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s),k(s)-1)&&A(i(s),j(s),k(s))>A(i(s),j(s)-1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s),j(s)+1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)-1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)-1,j(s)+1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)+1,k(s)-1)&&A(i(s),j(s),k(s))>A(i(s)+1,j(s)-1,k(s)-1))
f=f+1
i(s)
j(s)
k(s)
end
end
end
I don't have the image processing toolbox, so cannot readily run your code. However, a quick review indicates to me that you're using the find function incorrectly. When provided with 3 outputs (as you have it), find doesn't return the 3D indices, but rather row, column, and a vector of the values. That means that k is just a giant vector of 1's, and so your for loop's if k(s)~=1 statement is never satisfied. You should do something like [i,j,k]=ind2sub(size(A),find(A~=0)) if you instead want the 3D indices.
Also, FYI, this:
for i=1:rmax
for j=1:cmax
for k=1:radmax
A(i,j,k)=0;
end
end
end
Can be replaced with A=zeros(rmax,cmax,radmax);.
I'm attempting to run this simple diffusion case (I understand that it isn't ideal generally), and I'm doing fine with getting the inside of the solid, but need some help with the outer edges.
global M
size=100
M=zeros(size,size);
M(25,25)=50;
for diffusive_steps=1:500
oldM=M;
newM=zeros(size,size);
for i=2:size-1;
for j=2:size-1;
%we're considering the ij-th pixel
pixel_conc=oldM(i,j);
newM(i,j+1)=newM(i,j+1)+pixel_conc/4;
newM(i,j-1)=newM(i,j-1)+pixel_conc/4;
newM(i+1,j)=newM(i+1,j)+pixel_conc/4;
newM(i-1,j)=newM(i-1,j)+pixel_conc/4;
end
end
M=newM;
end
It's a pretty simple piece of code, and I know that. I'm not very good at using Octave yet (chemist by trade), so I'd appreciate any help!
If you have concerns about the border of your simulation you could pad your matrix with NaN values, and then remove the border after the simulation has completed. NaN stands for not a number and is often used to denote blank data. There are many MATLAB functions work in a useful way with these values.
e.g. finding the mean of an array which has blanks:
nanmean([0 nan 5 nan 10])
ans =
5
In your case, I would start by adding a border of NaNs to your M matrix. I'm using 'n' instead of 'size', since size is an important function in MATLAB, and using it as a variable can lead to confusing errors.
n=100;
blankM=zeros(n+2,n+2);
blankM([1,end],:) = nan;
blankM(:, [1,end]) = nan;
Now we can define 'M'. N.B that the first column and row will be NaNs so we need to add an offset (25+1):
M = blankM;
M(26,26)=50;
Run the simulation through,
m = size(blankM, 1);
n = size(blankM, 2);
for diffusive_steps=1:500
oldM = M;
newM = blankM;
for i=2:m-1;
for j=2:n-1;
pixel_conc=oldM(i,j);
newM(i,j+1)=newM(i,j+1)+pixel_conc/4;
newM(i,j-1)=newM(i,j-1)+pixel_conc/4;
newM(i+1,j)=newM(i+1,j)+pixel_conc/4;
newM(i-1,j)=newM(i-1,j)+pixel_conc/4;
end
end
M=newM;
end
and then extract the area of interest
finalResult = M(2:end-1, 2:end-1);
One simple change you might make is to add a boundary of ghost cells, or halo, around the domain of interest. Rather than mis-use the name size I've used a variable called sz. Replace:
M=zeros(sz,sz)
with
M=zeros(sz+2,sz+2)
and then compute your diffusion over the interior of this augmented matrix, ie over cells (2:sz+1,2:sz+1). When it comes to considering the results, discard or just ignore the halo.
Even simpler would be to simply take what you already have and ignore the cells in your existing matrix which are on the N,S,E,W edges.
This technique is widely used in problems such as, and similar to, yours and avoids the need to write code which deals with the computations on cells which don't have a full complement of neighbours. Setting the appropriate value for the contents of the halo cells is a problem-dependent matter, 0 isn't always the right value.