Borrar filtros
Borrar filtros

Can you please explain how did he found the function?

1 visualización (últimos 30 días)
anonymous
anonymous el 12 de Mayo de 2021
Respondida: Star Strider el 12 de Mayo de 2021
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

Respuestas (1)

Star Strider
Star Strider el 12 de Mayo de 2021
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.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by