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

조회 수: 2(최근 30일)
Cate may 2020년 10월 28일
댓글: Rena Berman 2021년 5월 7일
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
댓글 수: 2표시숨기기 이전 댓글 수: 1
Rena Berman 2021년 5월 7일

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider 2020년 10월 28일
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:
.
댓글 수: 2표시숨기기 이전 댓글 수: 1
Star Strider 2020년 10월 28일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by