Error: Function definition not supported in this context. Create functions in code file.

5 次查看(过去 30 天)
function FixedPointIteration
%Fixed Point Iteration
Re=p*V*D/mu can be rewritten as Re= (1/mu)*P*V*D
D=.005;
V=40;
p=1.23;
mu=1.79*10*-5;
e=.0015;
function of Re;
Re=p*V*D/mu;%reynolds numbere quation
g=@(x)(1/sqrt(x)+2*log(e/(3.7*D)+2.51/(Re*sqrt(x))));
%x = f(x)
syms 'x'
f=@(x)(-1./(2*log(e/(3.7*D)+2.51/(Re*sqrt(x))))).^2;
x=.08;
i=1;
while abs(g(x))> 1e-9
x=f(x);
end
fprintf('Root found: %.10f\n'x)
fprintf('Function value at root %E\n',g(x))

回答(1 个)

Walter Roberson
Walter Roberson 2020-12-13
编辑:Walter Roberson 2020-12-13
function of Re;
Wrong syntax for declaring a function.
Missing a % if it is intended to be a comment.
Re=p*V*D/mu can be rewritten as Re= (1/mu)*P*V*D
missing a % between the code and the comments
  1 个评论
Image Analyst
Image Analyst 2020-12-13
function x = FixedPointIteration()
% Fixed Point Iteration
D=.005;
V=40;
p=1.23;
mu=1.79*10*-5;
e=.0015;
% Define the Re function:
% Re=p*V*D/mu can be rewritten as Re= (1/mu)*P*V*D if you'd rather.
Re=p*V*D/mu; % Reynolds number equation
% etc.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by