Using An Equation As An Input Argument For A Function
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to write a function that takes an equation (fx) in as input argument and solves for it using two separate bounds (fl) (fu).
For example say the equation is: x^8-1.5=0
How would I go about getting the equation input as my fx value? Do I have to use f=@x somehow?
Thanks in advance for any help. ~Mike
0 个评论
回答(1 个)
Mischa Kim
2014-3-31
Mike, check out the code below:
function fun_test()
f = @(x) x^8 - 1.5;
xl = 0;
xu = 1;
sol = fun_solve(f, xl, xu);
disp(sol)
end
function fsol = fun_solve(f,xl,xu)
x = (xu + xl)/2;
fsol = f(x);
end
Since I'm not quite sure what exactly you would like to solve for, I am simply evaluating the function at the midpoint.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!