anyone here got matlab??
matrixlaboratory
The Language of Tec Computing?
botmean do u have matlab??
I don't man
please go download
I should
So is this a free advertisement for them hehe :P
no lol i need someone that can run mycodee
i do @dan815
really!! ok wait
can u see if this code runs 4 u
@dan815 its saying page not found
are you on your computer or phone
computer
ok in that case how about if u try copy pasting this code
function out=w03assignment2_method3() %Generating Normal set of 1000 points, a random set of numbers added to %each other over and over should yield a normally distributed set of data %in this case the mean should be 0.5 if i divide by the total normal of %data sets added together. %Step by Step of what my code is doing: % 1)First generate normally distributed data points to sample from % 2)defined my piecewise function in 'mclf' function and generated plot %3) determined a started plane pos, and plane error, at each increment the %plane's position changed +100+/- error. %4) Randomly selected 75 points, set all their weight to 100% or 1, then %the plane's detected height was acquired by mclf(plane_pos), this was %taken to be a guassian distribution at that point, wiht 500 std. This was %used to determine the weight, of the random sampled points. %w=p(xsamp)/p(current). This weight updated the current weight of the point %by taking a mean between the 2. % 5)If the weight dropped below some percentage. The point was dropped and, % another point closer to the higher weighted points was taken into % account. % 6)I created the sigmadiff function and made use of the normally % distributed data, to pick a normally distributed value and see the % standard deviation away from the mean, this way I will get more % deviations that are closer to the mean, and I devised a method where for % every 0.5 standard deviation I picked a lower weight point to distribute % the random point. This way not all the random points went to the highest % weight point. However a larger number did as that point is weighted % heigher to begin with. % 7)the new weight determined the new size, and thats about it. % 8)For this method there is something different going on when it comes to % the resampling stage, since the rejection criteria is very high, as soon % as the weight decreases below 0.9 it is discarded, however, the resampled % points are put at the lowest weight and set to 1, which bumps them down % the bottom of the list, when sorted befor each for loop, and in the next %iteration if they were put beside a good point at the top of the list, %they gradually cycle back up instead of dissappearing on the next check down, if % not they quickly drop below the rejection criteria and are discarded and % put beside another lower weighted point, but the lower weighted points % are stabilizing at the top as a result of cycling up the whole matrix, % so they are the converging points, and the new points sampled there are % even better gusses or very close to the right gusses, with this method we keep %producing points that are dropping in probability slower and slower, so you will be %saturated with high probability points all throughout the list, all above 0.9 prob atleast. % ------------------------ n_data=rand(1000,1) for i=1:999 n_data=n_data+rand(1000,1); end n_data=n_data./1000 std=sum((n_data-mean(n_data)).^2)/sqrt(1000) n_mean=mean(n_data) x=1:10000 for j= 1:10000 piece(j)=mclf(j); end %axis([0 10000 0 9000]) %plot(x,y) %planepos p_error=20*(rand-0.5) %plane starting at pos =0 p_pos=0 g=ones(75,2) g(1:75,1)=rand(75,1)*10000 count=0 while p_pos<=10000 count=count+1 clf p_error=20*(rand-0.5); p_pos=p_pos+100+p_error; hold all; plot(p_pos,8000,'o','MarkerSize',20) %plane localization(plane mean location) plot((mean(g(:,1))-100),8900,'*','MarkerSize',15) plot(x,piece) axis([0 10111 0 9200]) % %sorting the 75 by 2 matrix of position and weights with respect to the %weights of the points g=sortrows(g,2); %redistribute the weighting, the highest weight is always 1, the most %correlated weight gets bumped to a 1 and everythign is wrt to that. %this code below and the comment above is for method 2 %g(:,2)=g(:,2)/max(g(:,2)) for k=1:75 plot(g(k,1),8500,'o','MarkerSize',g(k,2)*10) %this gets the new weight from p(trial)/p(current) and then takes the mean %with the existing weight at that point and replaced the weight with it. g(k,2)=(g(k,2)+(gauss(mclf(g(k,1)),mclf(p_pos))/gauss(mclf(p_pos),mclf(p_pos))))/2; %if the weight of the point is less than 90% or located past the 10,000 %mark we replace the point with another guess, i made my guess normally %distributed around the highest weights with the help of the sigmadigg %function i defined at the bottom, every 0.5 deviation i get from my mean %from my normally distributed data, it will be one of m highest weighted %points to place the new guess around. if g(k,2)<0.90 | g(k,1)>10000 %numbo=randint(1,1,[1,1000]); numbo=randi(1000); guess=n_data(numbo); %this is the main difference in method 3, i am throwing my random guesses %around the worst weight which ended up there as a result of slowly cycling %up, the bad points dissappear faster without slowly cycling up to the %lowest weight g(k,1)=g((sigmadiff(n_mean,guess,std)),1)+200*(rand-0.5); g(k,2)=1 %g(k,2)=g((sigmadiff(n_mean,guess,std)),2); end % % if g(k,1)>=10000 % guess=n_data(1,1,randint([1,1000])) % g(k,1)=g(1,sigmadiff(n_mean,guess,std))+20*(rand-0.5) % g(k,2)=g(2,sigmadiff(n_mean,guess,std)) % % if g(k,1)>=10000 % g(k,1)=((count-1)*100+500-(count-1)*100)*rand+(count-1)*100 % end % if g(k,2)<0.05 % g(k,1)=((count-1)*100+500-(count-1)*100)*rand+(count-1)*100 % g(k,2)=0.9 % end % end g(:,1)=g(:,1)+100 % %g(1:75,1)=g(1:75,1)+100 ; % % plot(g,8500,'o','MarkerSize',10) p=getframe; end end %-----FuNCTION DEFINITIONs function out=mclf(x) if 1<= x & x <=1000 out=0; elseif 1000<x & x<=2000 out=x-1000; elseif 2000<x & x<=3000 out=x.*0.5; elseif 3000<x & x<=4000 out=x.*0.25+750; elseif 4000<x & x<=5000 out=x*0.6-650; elseif 5000<x & x<=6000 out=x.*-0.4+4350 elseif 6000<x & x<=7000 out=1950; elseif 7000<x & x<=8000 out=x.*-0.6+6150; elseif 8000<x & x<=9000 out=x.*(-0.9)+8550 elseif 9000<x & x<=10000 out=450; elseif x>10000 out=0; end end %Gaussian distribution function function out =gauss(x,m) sig=500; out=1/(sig*sqrt(2*pi)) * exp(-1/2*(((8000-x)-(8000-m))/sig)^2); end %picewise def function function out=mclf(x) if 1<= x & x <=1000 out=0; elseif 1000<x & x<=2000 out=x-1000; elseif 2000<x & x<=3000 out=x.*0.5; elseif 3000<x & x<=4000 out=x.*0.25+750; elseif 4000<x & x<=5000 out=x*0.6-650; elseif 5000<x & x<=6000 out=x.*-0.4+4350 elseif 6000<x & x<=7000 out=1950; elseif 7000<x & x<=8000 out=x.*-0.6+6150; elseif 8000<x & x<=9000 out=x.*(-0.9)+8550 elseif 9000<x & x<=10000 out=450; elseif x>10000 out=450; end end %sigmadiff func function out=sigmadiff(m,x,std) t=abs((m-x)/std); if 0<=t<0.5 out=1; elseif 0.5<=t<1 out=2; elseif 1<=t<1.5 out=3; elseif 1.5<=t<2 out=4; elseif 2<=t<2.5 out=5; elseif 2.5<=t<3 out=6; elseif 3<=t out=1; end end
this page may help http://www.mathworks.com/help/matlab/matlab_prog/nested-functions.html it explains how to nest functions
oh and you also have two identical lines that state "function out=mclf(x)" when I deleted one copy, the function worked for me
did u get the error for the downloaded code or the copy pasted not, which one i gotta fix its running fine for me
the thing is it might be running fine for me beccause i alread have files with the functions at the bottom defined so i wanna see if it runs for someone else who doesnt have the functiosn defined on their computer but now put at the bottom of the code
it runs fine for me I think, I get this after the animation plays out
ohh !! thanks for catching that double function hehe
here is my new code see how it works, basically the * is the plane approximation and the Big Circle is the true position of the plane and the small circles are the approximations for the plane location and the size of the small circles are how probable it is there
the first one is supposed to be the fast version and the 2nd one pauses to show how the new sample points are being regenerated
could you tell me if the 2nd one is running like way too slow on your computer
it runs pretty fast for me but my comp is fast, not sure how fast itll run on the school comps
the point of the simulation is to see how fast you can get the algorithm to localize aroung the point
when I try to run the second one, I get "Undefined function or variable 'w03assignment2_method3_f2'."
oh right, forgot to match up the names
the second one is definitely different (not sure how to explain what's going on)
the 2nd one is yeah, im not sure how to explain it aswell i just think its like showing the new sampled points after ever single change
Join our real-time social learning platform and learn together with your friends!