سؤال

I'm trying to do do some algebra in JavaScript based on some conditions and known variables but I'm not good enough at maths or JavaScript to understand how to write it.

So here's the conditions:

var w1 = h1/1.98

var w2 = h2/0.6355

h1 = h2

w1 + w2 = 1367

I'm not 100% sure but I think there may be enough info here to find out what w1, w2, h1 and h2 are.

Does anyone know how I can create this calculation?

هل كانت مفيدة؟

المحلول

Here is the solution with variables as you need:

function algebra(c1, c2) {
  /* Given these equations
  w1 = h1/c1
  w2 = h2/c2
  h1 = h2
  w1 + w2 = 1367; */

  var w1 = 1367 * c2 / (c1 + c2), h1 = w1 * c1;
  return {w1:w1, w2:1367-w1, h1:h1, h2:h1};
}

نصائح أخرى

If it is an algebra question... since h1 = h2 you may exclude them and get.

w1*1.98 = w2*0.6355
w1 + w2 = 1367

Put it into some solver and get

{ w1 = 332.1462435480787, w2 = 1034.853756451921 }.

I don't know if anyone's reading here any more, but here you go:

https://sourceforge.net/projects/matgts/files/jsmath/

Access "index.html". Some of the programs require at least Firefox 3 or 4, because of , but the one which solves systems of equations should run in earlier versions (and up to the latest one, of course). Easy to use, download and run offline, like JavaScript programs are always supposed to run. For accessing web sites, NetSurf is the best (https://www.netsurf-browser.org/), no JavaScript. JavaScript is a great language, just not online, where it's just a great nuisance.

A JavaScript function which uses Cholesky's method (the program mentioned above uses Gauss elimination) is included here:

https://sourceforge.net/projects/matgts/files/jswall/

The file is "js/chol.js", the comment above the function says how the elements of the matrix should be organized.

Equivalent C functions are also provided. All GPL version 3.

P.S. I tried to post the message with NetSurf and it didn't work, apparently this site has some serious problems, which I find surprising for a site about programming, I would have expected its creators to know something about the subject.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top