Page 1 of 1

I've created MATLAB code here that produces a graph and depending on parameters (some random) converges to a different a

Posted: Mon Mar 06, 2017 12:27 pm
by Charles
I want to be able to run this 100 times for a certain set of parameter values and take an average of the amount of groups that it produces.

Here is the code I have at the minute. Do I need to create another m file for this or can i do it within the function I've already created?

Code: Select all

function [t seqBeliefs] = extendedHK(n, tol, adj)
    %extendedHK Summary of function goes here
    %Detailed explanation goes here

    beliefs = rand(n,1);
    seqBeliefs = beliefs; %NxT matrix
    converge = 0;
    step = 0
    t = step


    while converge ~= 1
        step = step+1;
        t = [t step];
        A = zeros (n,n);

        for i=1:1:n
            for j=i:1:n
                 if abs(beliefs(i) - beliefs(j)) < tol && adj(i,j)==1
                     A(j,i)=1;
                     A(i,j)=1;
                 end
             end


         end




         beliefs = A*beliefs./ sum(A,2);
         seqBeliefs = [seqBeliefs beliefs];
          if sum(abs(beliefs - seqBeliefs(:,step)))<1e-12
             converge = 1;
         end
     end
     plot(t,seqBeliefs)
     end

     %%in command window type adj=random_graph(n) then call extendedHK                    function
     %%with same n then tol value and 'adj'