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

5 views (last 30 days)
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))

Answers (1)

Walter Roberson
Walter Roberson on 13 Dec 2020
Edited: Walter Roberson on 13 Dec 2020
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 Comment
Image Analyst
Image Analyst on 13 Dec 2020
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.

Sign in to comment.

Categories

Find more on Entering Commands in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!