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