Reputation: 11
I used Maple 2024 to find some big expressions which I want to use in Javascript for further calculations. In total there are 20 big expressions which I have in the format of Latex and Maple. The input parameters are all real positive values (1 can be 0, which is ok). But for some specific combinations of parameters, some values inside roots go below 0. I saw that the package "math.js" accepts complex values and can also calculate with them.
Unfortunately I have te rewrite my equations in a completely different format. Is there a tool or method to easily do this?
The smallest expression I have:
function expression(beddingsconstante, Phiy, L, EIyy) {
var bc = beddingsconstante;
var a_p = math.sqrt(math.add(Phiy * L ** 2 * math.sqrt(bc), math.sqrt(bc * Phiy ** 2 * L ** 4 - 576 * EIyy)));
var a_m = math.sqrt(math.subtract(Phiy * L ** 2 * math.sqrt(bc), math.sqrt(bc * Phiy ** 2 * L ** 4 - 576 * EIyy)));
var b_p = math.multiply(a_p, L * math.sqrt((6 * math.sqrt(bc)) / (144 * EIyy)));
var b_m = math.multiply(a_m, L * math.sqrt((6 * math.sqrt(bc)) / (144 * EIyy)));
var sh_b_p = math.sinh(b_p);
var ch_b_p = math.cosh(b_p);
var sh_b_m = math.sinh(b_m);
var ch_b_m = math.cosh(b_m);
return math.sqrt(6) * math.sqrt(EIyy) * bc ** (5 / 4) * ((Phiy ** 3 * a_m * sh_b_m * L ** 6 * (-1 * ch_b_p ** 2 + (ch_b_m + sh_b_p) * ch_b_p + ch_b_m * sh_b_p) * a_p * bc ** (3 / 2) - 432 * (Phiy * a_m * sh_b_m * L ** 2 * (-1 * ch_b_p ** 2 + (ch_b_m + sh_b_p) * ch_b_p + ch_b_m * sh_b_p) * a_p * math.sqrt(bc) + 192 * EIyy * (sh_b_m ** 2 * ch_b_p + ch_b_m * sh_b_p * (-1 * ch_b_p + ch_b_m + sh_b_p))) * EIyy) * math.sqrt(L ** 4 * Phiy ** 2 * bc - 576 * EIyy) + a_p * sh_b_m * a_m * (L ** 4 * Phiy ** 2 * bc - 576 * EIyy) * (L ** 4 * Phiy ** 2 * bc - 144 * EIyy) * (ch_b_p - sh_b_p) * (ch_b_m - ch_b_p)) / ((L ** 2 * sh_b_p * bc * Phiy * (L ** 4 * Phiy ** 2 * bc - 432 * EIyy) * sh_b_m - 144 * EIyy * math.sqrt(bc) * a_m * a_p * (ch_b_m * ch_b_p - 1)) * (Phiy * (a_p * sh_b_m + (-1 * ch_b_p + ch_b_m + sh_b_p) * a_m) * math.sqrt(bc) * L ** 2 * math.sqrt(L ** 4 * Phiy ** 2 * bc - 576 * EIyy) + (-a_p * sh_b_m + (-1 * ch_b_p + ch_b_m + sh_b_p) * a_m) * (L ** 4 * Phiy ** 2 * bc - 288 * EIyy)))
}
// Case 1 (correct):
// answer: 9755211.200
L = 1000;
E = 30000;
v = 0.2;
G = E/(2*(1+v));
EA = E*200*500;
EI__yy = E*1/12*200*500**3;
GA__y = 5/6*G*200*500;
k = 100000;
Phi__y = 12*EI__yy / (GA__y*L**2);
console.log(expression(k, Phi__y, L, EI__yy));
// Case 2 (wrong):
// answer: 471203.9805 - 0.0001033745968*I
L = 1000;
E = 30000;
v = 0.2;
G = E/(2*(1+v));
EA = E*200*500;
EI__yy = E*1/12*200*500**3;
GA__y = 5/6*G*200*500;
k = 100;
Phi__y = 12*EI__yy / (GA__y*L**2);
console.log(expression(k, Phi__y, L, EI__yy));
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/12.4.0/math.js"></script>
As you may see, all the variables are already in the good format. But I was not so happy to do that for 20 huge expressions... Any idea how I could do this easily?
Edit:
I added an additional case so you can see it works, but for some specific combination of values not (because it becomes a complex number)
Upvotes: 0
Views: 53