Can you please explain how did he found the function?

조회 수: 1 (최근 30일)
anonymous
anonymous 2021년 5월 12일
답변: Star Strider 2021년 5월 12일
This is my teacher's solution. But, I didn't get the part about the function. Can you explain how did he get the fun?
% create the vector V
V=100:10:200; % with step size 10
% create the vector F
F=10:1:100;
% intialize a matrix X with zeros
X=zeros(length(V),length(F));
x0=0; % initial guess
% define the equation to find x using function handle @
fun=@(x,V,F,k,n,c0) (x./(k*c0^n*(1-x).^n))-V/F; % paramterized function
for i=1:length(V)
for j=1:length(F)
% all the constants
c0=2;
n=2;
k=0.9;
v=V(i);
f=F(j);
% define another function using function handle @
myfun=@(x) fun(x,v,f,k,n,c0); % function of x alone
x=fzero(myfun,x0); % zero of the function myfun
X(i,j)=x; % store the value x
end
end
% since X is a matrix,max(X) will return a vector of maximum of each
% column of the matrix X
% so taking max(max(X)) will return maximum value for x
xmax=max(max(X));
[i,j]=find(X==xmax); % get the index of xmax
% get the respective value of V and F
v=V(i);
f=F(j);
fprintf('Maximum value of x is %f for V=%d and F=%d',xmax,v,f);
% plotting
surf(F,V,X) % here x=F,y=V,Z=X

답변 (1개)

Star Strider
Star Strider 2021년 5월 12일
I am not certain what you are asking.
If it is to understand this —
fun=@(x,V,F,k,n,c0) (x./(k*c0^n*(1-x).^n))-V/F; % paramterized function
‘fun’ is an anonymous function to be used with fzero.
To find out where an expression equals a specific value (the value to the left of the equal sign), subtract that value from it (here ‘V/F’ and solve for the zero-crossing, because it will be 0 at that value of ‘V/F’.
If you questions is about something else, please be more specific.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by