How to solve a transcendental equation?

Hello everyone,
How do I solve the transcendental equation as shown below for 'th'?. All the other variables (z0, tp, v1, y0, x0 and theta01) are known. However the equation is part of a code and the variables (z0, tp, v1, y0, x0 and theta01) are inputs of a function and it will be chosen by the user. So, whenever they input any value for those 6 variables the 'th' must be the output. I've tried to bring only 'th' to one side of the equation but I think is impossible.
Note: I'm new in Matlab. So, please, try to be as clear as possible. Thank you.

Answers (2)

See the "Root of Function with Extra Parameter" example on the documentation page for the fzero function. Using the terminology from that example, myfun would be a function of th, z0, tp, v1, y0, x0, theta01 that when evaluated would return
(z0 + sqrt(...)) - (v1*th*sin(theta01) + 1/2*g*tp*(tp-2*th))
Then define values for all the variables except th, define fun to be:
fun = @(th) myfun(th, z0, tp, v1, y0, x0, theta01);
and pass fun into fzero.

2 Comments

Dear Steve,
I am trying to follow your steps. However I'm still getting an error as you can see from below:
"Exiting fzero: aborting search for an interval containing a sign change because complex function value encountered during search. (Function value at 0.680201 is -2.7828+1.798i.) Check function or try again with a different starting value."
For the given data, the value of th should be 0.7013308212 as you can see from the example below. That's the exactly function I'm trying to create a code to solve it.
This is how I've written so far:
myfun = @(th, z0, tp, v1, y0, x0, g, theta1) z0+sqrt((4*(th-tp)^2)*v1^2-y0^2-(-x0+v1*th*cos(theta1))^2) - v1*th*sin(theta1)-(1/2)*g*tp*(tp-2*th);
z0 = 0; v1 = 10; tp = 0.1; y0 = 11; x0 = 10; g = 9.81; theta1 = pi/6;
fun = @(th) myfun(th, z0, tp, v1, y0, x0, g, theta1);
th = fzero(fun,0.7);
Hope you can take a look again and help me.
Thank you.
Regards.
When I look at the graph of your function using this command:
fplot(fun)
I see that the zero is pretty close to the value of th where the value of fun becomes complex due to the quantity under the square root sign becoming negative. [That's somewhere between 0.686218 and 0.686220.] When I specify an interval that contains the zero instead of just a single point, it works.
th = fzero(fun, [0.69 1])
The upper bound probably doesn't matter too much (as long as it's not extremely large) but the lower bound needs to be between the point where fun turns complex and the zero.

Sign in to comment.

syms z0 th tp v1 y0 x0 theta1 g
solve(z0+sqrt((4*th-tp)^2*v1^2-y0^2-(-x0+v1*th*cos(theta1))^2) == v1*th*sin(theta1)+(1/2)*g*tp*(tp-2*th),th)
You have a quadratic, so there will be two solutions. The equation is not transcendental with respect to the variable of interest, th.

2 Comments

Dear Walter,
I am trying to follow your steps. However I'm still getting an error as you can see from the picture below:
For the given data, the value of th should be 0.7013308212 as you can see from the example below. That's the exactly function I'm trying to create a code to solve it. The way I'm writing your code is not giving me two solutions as you mentioned and as you could see.
Look the example:
This is how I've written so far:
syms z0 th tp v1 y0 x0 theta1 g
z0 = 0; v1 = 10; tp = 0.1; y0 = 11; x0 = 10; g = 9.81; theta1 = pi/6;
solve(z0+sqrt((4*th-tp)^2*v1^2-y0^2-(-x0+v1*th*cos(theta1))^2) == v1*th*sin(theta1)+(1/2)*g*tp*(tp-2*th),th)
Hope you can take a look again and help me.
Thank you.
Regards.
What do you get for x if you use
x=vpa(solve(...))
?
Best wishes
Torsten.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 9 May 2017

Commented:

on 10 May 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!