Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do I call a function within another function AND How do I input known variables in function?

1 回表示 (過去 30 日間)
MUNKHBOLOR BAIGALI
MUNKHBOLOR BAIGALI 2020 年 9 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello. I want to write below equation in matlab code. in this problem unknown variable is x = optimalsize(0 , 2 , 5, 7, 8 , 9 , 10kW) and others known. BUT I have 3 questions.
  1. how to input known variables in this function?
  2. how to call Tc function in P function ?
  3. how to know which number is optimal size
I tried to write below equation in matlab code. but it doesn't work.
PLEASE, Help me
function [P, Tc] = stfunction(Ppv_rated, x, G , Gref, Kt, Tref, Tamb)
Tc = @ndfunction;
P = (Ppv_rated * x) * (G/Gref)*(1 + Kt*(Tc - Tref));
function Tc = ndfunction(Tamb, G)
Tc = Tamb + (0.0256 * G);
disp(P)
end
end
PLEASE!!!

回答 (1 件)

Monisha Nalluru
Monisha Nalluru 2020 年 9 月 16 日
For the above question
  1. The known values are sent into function as parameters
  2. The function Tc can be called directly or can be called using function handle
Please refer functions, nested function, anonymous function documentation for better understanding
Since the problem is to find optimal size for different x values. We first need to iterate through x and calculate the Ppv-out
As example
x=[0,2,5,7,8,9,10]; % x-values given
ppv_out=[]; % output gor each x-value
% declare the ppv_rated,G,Gref,kt,Tref,Tamb
for i=1:length(x)
ppv_out(i)=stfunction(ppv_rated,x,G,Gref,kt,Tref,Tamb);
end
function [P] = stfunction(Ppv_rated, x, G , Gref, Kt, Tref, Tamb)
Tchandle = @ndfunction; % function handle created
Tc=Tchandle(Tamb,G); % Tc value is calculated
P = (Ppv_rated * x) * (G/Gref)*(1 + Kt*(Tc - Tref)); % ppv_out calcuated
function Tc = ndfunction(Tamb, G)
Tc = Tamb + (0.0256 * G);
end
disp(P) % display the calcualted P value
end

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by