필터 지우기
필터 지우기

How to get the value of an extra variable with fsolve

조회 수: 14 (최근 30일)
As an example, we have the following approach to find f:
%% Known data
D=0.1;%m
V=10;%m/s
nu=8.94e-7;%m^2/s
epsilon=4.6e-5;%m
%% Calculation of f
f_est=0.02;
f=fsolve(@f_Col,f_est,[],V,nu,D,epsilon);
%% Functions
function [F]=f_Col(f_est,V,nu,D,epsilon)
% function that calculates the friction factor with the Colebrook equation
% for a specific V, D and epsilon
Re=D.*V/nu;
rr=epsilon/D;
F=1./sqrt(f_est)+2*log10(rr/3.7+2.51./(Re.*sqrt(f_est)));
F=F';
end
Is there a way to receive the rr and Re values ​​when using the fsolve? In this case these two values ​​do not depend on the value of f that solves the equation, but just as an example, is there a way to do it?

채택된 답변

John D'Errico
John D'Errico 2020년 7월 7일
편집: John D'Errico 2020년 7월 7일
The simple trick is to use the output arguments from a function.
Change your function header to look like this:
function [F,rr,Re]=f_Col(f_est,V,nu,D,epsilon)
When you use a function that return multiple output arguments, if you only ask for one output, it only gives you the first output. Fsolve will ignore those other outputs.
Now, after fsolve returns a value for f, call the function ONE more time, with the final value of f, but now with additional outputs. Call it like this:
[~,rr,Re]=f_Col(f,V,nu,D,epsilon);
You see that now you are taking the values of rr and Re, as computed when f is the final value from fsolve. We are not interested in the first output argument, so tell MATLAB to dump it in the bit bucket.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Design Optimization에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by