Use fzero() to calculate x required to achieve V/F for every combination of V and F.

2 vues (au cours des 30 derniers jours)
Hi,
I have a formula ((x)/((k*c0^n)(1-x)^n) that predicts the conversion of a reaction (x) based on different reactor volumes (V) and flow rates (F). I would like to use fzero() to find the conversion (x) required to achieve V/F for every combination of V and F.
I then want to plot x against V and F using surf().
The code I have so far is below, I'm struggling to use fzero() as each time I run it I get errors and Im not sure if that's because my initial guess does not contain a root or If I have to re-arrange my V/F equation to make x the product before using fzero().
Thanks
k = 0.9;
n = 2;
c0 = 2; %initial concentration (mol/m^3)
V = 100:10:200;
F = 10:1:100;
%initial guess = 0.5 (can be anything)
V/F = @(x) (x)/((k*c0.^n)*((1-x)^n));
fun = @(x) V/F;
x = fzero(fun,0.5)
%To plot
%surf()
%figure(5) %figure 5

Réponse acceptée

Star Strider
Star Strider le 28 Oct 2020
The fzero function is a root-finder, so the function it is given to solve must equate to 0 for any delection of independent variables. I implemented that approach in the revised coding of ‘fun’ here:
k = 0.9;
n = 2;
c0 = 2; %initial concentration (mol/m^3)
V = 100:10:200;
F = 10:1:100;
V = linspace(100, 200, 25);
F = linspace(10, 100, 50);
%initial guess = 0.5 (can be anything)
VF = @(x) (x)./((k*c0.^n)*((1-x).^n)); % Not Directly Used
fun = @(x,V,F) V./F - (x)./((k*c0.^n)*((1-x).^n));
for k1 = 1:numel(V)
for k2 = 1:numel(F)
x(k2,k1) = fzero(@(x)fun(x,V(k1),F(k2)),0.5);
end
end
figure
surfc(V, F, x)
grid on
xlabel('V')
ylabel('F')
zlabel('Conversion')
view(130,10)
produces:
.

Plus de réponses (0)

Catégories

En savoir plus sur Function Handles dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by