Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear all;
- close all;
- load('Idata.mat'); %loading the I(V) data
- plot(volt,curr) %plotting the data
- xlabel('Voltage'); %labelling the x axis
- ylabel('Current'); %labelling the y axis
- title('Current as a function of Voltage I(V) ') %title for the graph
- lv=length(volt); %Determining the number of voltage values
- lc=length(curr); %determning the number of current values
- x1=randi(lv,1); %This will produce a random voltage value
- x2=randi(lc,1); %This will produce a random current value
- y=volt(x1); %Matches the corresponding value of current value from the randomly selected voltage value
- yn=volt(x2); %Matches the corresponding value of voltage value from the randomly selected current value
- p=curr(x1); %Matches the corresponding value of current value from the randomly selected voltage value
- pn=curr(x2); %Matches the corresponding value of voltage value from the randomly selected current value
- while abs(pn-p)>10e-12 % This makes sure the iterrations will only run if the changes are greater than our 'tolerance'
- 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
- [a,b]=min(abs(volt-t)); %Returns the minimum element in the array of values
- p=pn; % Making the values of voltage and current the same
- pn=curr(b); % This will make the voltage equal the current at the minimim point in the array worked out in the line above
- y=yn; % Making the value of the randomly selected voltage and current the same.
- yn=t; % This is finding the value for which the voltage equals zero ( Voltage Dissapears )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement