Basic Mathematics (on MATLAB & Simulink)

222 Views Asked by At

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.

3

There are 3 best solutions below

0
On

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.

3
On

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$);

0
On

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?