-2

How do I easiest solve an equation=0 with a function as a parameter?

My function with one input variable is called potd(angle), with one output variable, potNRGderiv. I tried:

syms x

solve(potd(x))

This gave me error: Undefined function 'sind' for input arguments of type 'sym'.

Have you got any ideas? Thanks in advance.

Christian
  • 1
  • 1

1 Answers1

0

solve is the wrong avenue here, unless your function can be rewritten as a simple equation. solve uses muPAD functions which is why you can do solve(sin(x)) but not solve(sind(x)). You can, of course, just do the conversion yourself.

If your function is more complicated or you'd rather not rewrite it, look into fsolve:

x = fsolve(@myfun,x0)

Where x0 is your initial guess - i.e. myfun(x0) is close to 0 - and myfun is a function which takes x and returns a single output. Depending on what your function does, you may have to adjust the options using optimoptions (tolerance, step size, etc) to get a good result.

nkjt
  • 7,825
  • 9
  • 22
  • 28