Question
Help with Matlab -- I wrote a function file for the false position method and am trying to use it in a command window to
Help with Matlab -- I wrote a function file for the false position method and am trying to use it in a command window to find cd in the drag equation -- 0=sqrt((gm)/cd)tanh(sqrt((gcd)/m)t), using the following constants:
m=95, v=46, t=9, g=9.81
I tried typing the following in a command window, but am getting errors (such as 'unrecognized function or variable 'm').
f=sqrt((gm)/cd)tanh(sqrt((gcd)/m)t)
[root fx ea iter]=FalsePosition(f,0,1,0.05,20)
function[root,fx,ea,iter]=FalsePosition(func,xl,xu,es,maxit) m=95; V=46; t=9; dvdt=V/t; g=9.81;
if nargin<3 %if the number of input arguments (nargin) is less than 3 error('at least 3 input arguments required') end
if nargin<4||isempty(es) %if the number of input argument (nargin) is less than 4 OR es is not given (isempty) es=0.005; end if nargin<5||isempty(maxit)%if the number of input argument (nargin) is less than 5 OR maxit is not given (isempty) maxit=50; end
iter=0; xr=xl; ea=100;
while (1) xrold=xr; xr= xu-((f(xu)*(xu-xl))/(f(xu)-f(xl))) iter=iter+1; test=func(xl)*func(xr);
if test<0 xu=xr; elseif test>0 xl=xr; else ea=0 end
if ea <= es || iter >= maxit %get out from the while loop if the following criteria has been met. break end end
root=xr;fx=func(xr);
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started