If you are using R2016b or later you can use
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
function F = root2d(x)
F(1) = 1/sqrt(x(1)) + 2*log10((2.51*0.00001655)/(x(2)*0.267*sqrt(x(1))))
F(2) = 20 - x(1)*(300/0.267)*((x(2))^2/(2*9.81))
end
all in the same file (but you must use a file name that is not root2d.m )
If you did that then you could click the Run button in the editor to execute the code.
With earlier versions of MATLAB you could do something similar but you would need to use a function, such as
function drive_root
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
end
function F = root2d(x)
F(1) = 1/sqrt(x(1)) + 2*log10((2.51*0.00001655)/(x(2)*0.267*sqrt(x(1))))
F(2) = 20 - x(1)*(300/0.267)*((x(2))^2/(2*9.81))
end
Both of those could go in the same file, which in this example would be named drive_root.m . You could then run the code by clicking the green Run button in the editor.
Best Answer