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))
0 个评论
回答(1 个)
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
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 Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!