how to update the code as it takes an array of values of Vpv and return Ipv , ( can take Vpv = 0.1:0.1:1.2)..................
조회 수: 13 (최근 30일)
이전 댓글 표시
Main code:
clc
clear all
Vpv=0.9;
Ipv0 = 1;
global Np Ns Isc q T k Io n
Np = 1;
Ns=72;
Isc =1.82;
q= 1.6e-19;
T=298;
k=1.38e-23;
Io= 1.2987e-4;
n=1.8405;
x= fsolve(@pvcurve,Ipv0);
Function code:
function F = pvcurve(Ipv)
Vpv=0.9;
global Np Ns Isc q T k Io n
Np = 1;
Ns=72;
Isc =1.82;
q= 1.6e-19;
T=298;
k=1.38e-23;
Io= 1.2987e-4;
n=1.8405;
F = -(Ipv)+ (Np*Isc)- Np*Io*((exp((q*Vpv)/(n*k*T*Ns))-1));
question:
HOW to update the code so that it takes an array of values for Vpv and returns an array of Ipv. (It can be done by creating a 'for' loop in the main file, run it for the number of elements present in the array Vpv (let's say Vpv=0.1:0.1:1.2). Then put your command x= fsolve(@pvcurve,Ipv0) within the for loop. So, each time the fsolve function will solve the 'pvcurve' for different values of Vpv.
댓글 수: 0
답변 (1개)
Himanshu
2024년 10월 25일 5:00
Hey,
To update your code so that it returns a corresponding array of Ipv values, you can implement a for loop in your main script. This loop will iterate over each value in the Vpv array, solve for Ipv using fsolve, and store the results. Here’s how you can modify your code:
Main Code:
clc;
clear all;
% Array of Vpv values
Vpv_array = 0.1:0.1:1.2;
% Initialize array to store Ipv results
Ipv_results = zeros(size(Vpv_array));
% Initial guess for Ipv
Ipv0 = 1;
% Global variables
global Np Ns Isc q T k Io n Vpv
Np = 1;
Ns = 72;
Isc = 1.82;
q = 1.6e-19;
T = 298;
k = 1.38e-23;
Io = 1.2987e-4;
n = 1.8405;
% Loop over each Vpv value
for i = 1:length(Vpv_array)
Vpv = Vpv_array(i);
Ipv_results(i) = fsolve(@pvcurve, Ipv0);
end
% Display results
disp('Vpv values:');
disp(Vpv_array);
disp('Corresponding Ipv values:');
disp(Ipv_results);
Function Code:
function F = pvcurve(Ipv)
global Np Ns Isc q T k Io n Vpv
F = -(Ipv) + (Np * Isc) - Np * Io * (exp((q * Vpv) / (n * k * T * Ns)) - 1);
end
Hope this is helpful!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!