Pedro Guaraldi - 1 year ago 120

Vb.net Question

I am creating a program that calculates the temperature distribution of a slab based on some boundary conditions using Visual Basic. During the development, I need to solve equations like this one:

`tan(x*L) = x * (H1 + H2) / (x^2 - H1*H2)`

The variable in this case is x, and the constants L, H1 and H2 are given. I don't believe Visual Basic has a native solver so I need help in this one.

Thanks in advance,

Pedro Guaraldi

Answer Source

You can do this with a nonlinear solver and I'm sure there are solvers that have an interface you can use from VB. Alternatively you can write a file and call a solver as a subprocess.

Here's an example in AMPL that illustrates the idea:

```
# test.ampl
param H1 = 3;
param H2 = 4;
param L = 5;
var x >= 0.1; # set lower bound to 0.1, because 0 is a trivial solution
s.t. c: tan(x*L) = x * (H1 + H2) / (x^2 - H1*H2);
option solver knitro;
solve;
print x;
```

this produces the following output:

```
KNITRO 9.1.0: Locally optimal solution.
objective 0; feasibility error 6.08e-11
6 iterations; 7 function evaluations
Objective = find a feasible point.
1.701346690729009
```