Trying to calculate the height but get an error
Show older comments
I´m trying to calculate the h1 in from the equations A1 and A2 where i want to say that they are both equal to each other but i get an error saying:
Undefined function 'eq' for input arguments of type
'function_handle'
on the third line on code, is it wrong to say A1==A2? or how should i write it to make sure it take the two equations equal to each other?
A1 = @(h1) (H + b*tan(OS))- sqrt((H+b*tan(OS)^2 - h1));
A2 = @(h1) (((h0-h1)*tan(IS))*(ln(H/(H-h1))))/(tan(OS));
fcn = @(h1) A1==A2;
h1 = fzero(fcn,1)
Answers (1)
Steven Lord
on 21 Apr 2020
You're trying to solve for an h such that A1(h) = A2(h)? If rewrite that slightly to be in the form given in the documentation for fzero we want an h such that A1(h)-A2(h) = 0.
Your fcn doesn't evaluate the left side of that equation. So let's call fzero on that left side.
fcn = @(h1) A1(h1)-A2(h1);
h1 = fzero(fcn, 1)
Now you can check the answer in two different ways.
fcn(h1) % Should be close to 0
[A1(h1); A2(h1)] % First and second rows should be close to the same number
Arithmetic operators (like +) and the relational operators (like ==) aren't defined for function handles. Generally speaking, if you want to add or compare (etc) function handles you should add or compare (etc) the values obtained by evaluating those function handles instead.
1 Comment
Ervin Musinovic
on 21 Apr 2020
Categories
Find more on Mathematics 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!