0
$\begingroup$

I need some help for the below equation, is there any function which could help me to solve for b variable in MATLAB & Simulink? Otherwise, which numerical methods would you prefer?

$$\frac{a-b}{2 R}=2 I \sinh(\frac{a+b}{2 V}) $$

(assume that $a$, $R$, $I$ and $V$ is known)

Thanks.

$\endgroup$
2
$\begingroup$

Use fzero in matlab. Couple this with writing your function as $$ f(b) = 2I\sinh\left(\frac{a+b}{2V}\right)-\frac{a-b}{2R} $$ and use the example in the link.

$\endgroup$
2
$\begingroup$

fminsearch is a very general optimization function which you could use to minimize the error, i.e. to minimize $|f(b) - 0|$. If a solution exists, then that norm expression should be 0. It is a very useful function if you have a small and simple problem you need a fast solution to.

However, as your function is differentiable with respect to the variables, you may want to use a numerical scheme like fzero that Chinny84 proposed above.

Both of these functions you need to know how to pass on functions to other functions:

f = @(b) 2*I*sinh((a+b)/(2*V)) - (a-b)/(2*R);

Then you pass it on as :

b_solution = fzero(f,$b_0$);

$\endgroup$
  • $\begingroup$ +1. Do you mean differentiable for all variables in the equation or the variable you are trying to find the root for? I am honest in that I did not know that was a criterion and I have worked on this area. $\endgroup$ – Chinny84 Aug 13 '15 at 13:58
  • $\begingroup$ fzero only "knows" about the symbols in $b$. Everything else should be hidden for it as it is "encapsulated" into the function $f$. If you check "optimset", you see that you can pass options regarding gradient and jacobians to the algorithm, so it would be reasonable to believe it's inner workings can use those things. $\endgroup$ – mathreadler Aug 13 '15 at 14:56
  • $\begingroup$ Although I know the $fminsearch$ uses Melder-Nead which is a non-differentiable method. Will likely be slower for most smooth functions, but could perform better on non-smooth functions. $\endgroup$ – mathreadler Aug 13 '15 at 15:07
0
$\begingroup$

fun = @(b)2*sinh((0.5+b))-((0.5-b)/(2*1000));

x0 = [0.5];

x = fzero(fun,x0);

It works on MATLAB, thank you Chinny84, however, I need to use this (or any alternative) function on Simulink, but MATLAB says: "Code generation does not support anonymous functions.". Is there any way to use this function on Simulink?

I do not need to code generate, so I use "coder.extrinsic" but it does not work (I might have done something wrong). Should I solve this equation via Trapezoidal Rule or something like this, or is there any supported function?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.