Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.80 KB | None | 0 0
  1. clc;
  2. clear all;
  3. close all;
  4.  
  5. load('Idata.mat');  %loading the I(V) data
  6. plot(volt,curr)     %plotting the data
  7. xlabel('Voltage');  %labelling the x axis
  8. ylabel('Current');  %labelling the y axis
  9. title('Current as a function of Voltage   I(V) ') %title for the graph
  10.  
  11. lv=length(volt);    %Determining the number of voltage values
  12. lc=length(curr);    %determning the number of current values
  13.  
  14. x1=randi(lv,1);     %This will produce a random voltage value
  15. x2=randi(lc,1);     %This will produce a random current value
  16.  
  17. y=volt(x1);         %Matches the corresponding value of current value from the randomly selected voltage value
  18. yn=volt(x2);        %Matches the corresponding value of voltage value from the randomly selected current value
  19.  
  20. p=curr(x1);         %Matches the corresponding value of current value from the randomly selected voltage value
  21. pn=curr(x2);        %Matches the corresponding value of voltage value from the randomly selected current value
  22.  
  23. while abs(pn-p)>10e-12 % This makes sure the iterrations will only run if the changes are greater than our 'tolerance'
  24.    
  25.     t=yn-(pn*((yn-y)/(pn-p)));      %This is working out the change in volts over change in current,i.e dy/dx(Gradient), where t would be the y intercepts on the graph
  26.     [a,b]=min(abs(volt-t));         %Returns the minimum element in the array of values
  27.    
  28.     p=pn;                           % Making the values of voltage and current the same
  29.     pn=curr(b);                     % This will make the voltage equal the current at the minimim point in the array worked out in the line above
  30.     y=yn;                           % Making the value of the randomly selected voltage and current the same.
  31.     yn=t;                           % This is finding the value for which the voltage equals zero ( Voltage Dissapears )
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement