Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » Bazaar » New package MathTools
New package MathTools [message #45707] Sun, 27 December 2015 11:38 Go to next message
koldo is currently offline  koldo
Messages: 3121
Registered: August 2008
Ultimate Member
Many times I see scientists and engineers using expensive over bloated tools like Matlab and Diadem for very simple issues. Even open source options like Scilab or Octave are big applications and some activities are not very evident, complex to be done.

New package MathTools includes simple math tools for scientists and engineers.

- Calculator is a text calculator that handles variables and some mathematical functions.
- Regression permits to paste numerical series and automatically searches for the equation that fits best.

These are utilities that I use frequently and I expect they could be useful for you.

Many improvements are possible always depending on the scarce time availability

If anybody may want to add new features, all of them and even new applications related with the subject will be acknowledged.


Best regards
Iñaki
Re: New package MathTools [message #45709 is a reply to message #45707] Sun, 27 December 2015 14:22 Go to previous messageGo to next message
deep is currently offline  deep
Messages: 219
Registered: July 2011
Location: Bangalore
Experienced Member
Hi Koldo,

I liked the concept.
I would like to add custom constants.

I tried to add it.
gridConstants.Add("DegToRad",M_PI/180.0);
Constants are not accessed for calculation from ArrayControl. It is internal to ScatterDraw/Equation.cpp

eval.constants.Add("DegToRad",M_PI/180.0);
'Upp::EvalExpr::constants': cannot access private member
     declared in class 'Upp::EvalExpr'


After looking at the code the I found constants are defined in ScatterDraw/Equation.cpp

Any hints on how have custom constants.


Warm Regards

Deepak

[Updated on: Sun, 27 December 2015 15:00]

Report message to a moderator

Re: New package MathTools [message #45710 is a reply to message #45709] Sun, 27 December 2015 20:54 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3121
Registered: August 2008
Ultimate Member
Easy solution. Now constants and functions are public Smile

Best regards
Iñaki
Re: New package MathTools [message #51629 is a reply to message #45710] Mon, 22 April 2019 12:19 Go to previous messageGo to next message
peterh is currently offline  peterh
Messages: 46
Registered: November 2018
Location: Germany
Member
Hello I have a question about Mathtools:

It was initially my intention to tinker with it and add a "||" operator, which is really useful for electronics.
(Rp = R1*R2/(R1+R2) or Rp=1 /(1/R1 + 1/R2). If resistors are zero, then division by zero happens.)

When I input an expression in the calculator that divides by zero I get an exception.
When I restart the program, I cannot longer create variables.
This error persists even after I deleted Mathtools.json and even after rebooting.
I tried this on two different computers with the unmodified source and so I am pretty sure about this.

So the program must store some persistent data elsewhere. Where should I look?
I tried with the debugger but so far without success.

[Updated on: Mon, 22 April 2019 12:42]

Report message to a moderator

Re: New package MathTools [message #51645 is a reply to message #51629] Tue, 23 April 2019 09:35 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3121
Registered: August 2008
Ultimate Member
Thank you peterh

In fact MathTools had a problem that avoid to create new variables, by itself (nothing related with serialization) Rolling Eyes
I think all is fixed now. In addition , operator || is added. Smile


Best regards
Iñaki
Re: New package MathTools [message #51648 is a reply to message #51645] Tue, 23 April 2019 10:47 Go to previous messageGo to next message
peterh is currently offline  peterh
Messages: 46
Registered: November 2018
Location: Germany
Member
I thank you very much! This makes the program very useful for me and it it will be the only calculator I use in future! Smile

Is it possible for me to understand the problem?
Because the problem was persistent even after reboot, I conclude, the program stores some persistent information, on disk or in registry or in temp.
I did not find this in the source and temp should be deleted after reboot, so I currently dont understand the problem.

Thanks and regards,

Peter

[Updated on: Tue, 23 April 2019 11:15]

Report message to a moderator

Re: New package MathTools [message #51649 is a reply to message #51648] Tue, 23 April 2019 11:43 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3121
Registered: August 2008
Ultimate Member
Hi Peterh

The problem was in calculator.cpp, EvalExpr2::Eval2(). When an assignment was entered, new variable is checked in line 140 if it is a constant in IsConstant(sid). Before the fix, IsConstant() always returned true. Rolling Eyes



Best regards
Iñaki
Re: New package MathTools [message #51650 is a reply to message #51649] Tue, 23 April 2019 12:11 Go to previous messageGo to next message
peterh is currently offline  peterh
Messages: 46
Registered: November 2018
Location: Germany
Member
Thank you!
This program is beyond my prograqmming skills, but I nevertheless try to understand it. - partially
Anyway, variables worked before I had input 1/0. Rolling Eyes
Re: New package MathTools [message #51660 is a reply to message #51650] Wed, 24 April 2019 07:29 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3121
Registered: August 2008
Ultimate Member
Mysteries may exist Twisted Evil
Either way, they've been resolved Smile
If you have any idea for a new "math" "tool", we may include it.


Best regards
Iñaki
Re: New package MathTools [message #51666 is a reply to message #51660] Wed, 24 April 2019 10:31 Go to previous messageGo to next message
peterh is currently offline  peterh
Messages: 46
Registered: November 2018
Location: Germany
Member
Hi Koldo,

I got calculator.cpp and Mathtools.lay from the GIT website.
There where only minor modifications.

It compiled, but the behavior was unchanged.
I think GIT is not up to date yet.

Are the modifications today or tomorrow in nightly build?

Edit:

I downloaded nightly build and first test where very positive Smile
I always wanted a calculator with parallel operator and now I have it.
Thank you so much!!!

Ok, at second look there is a small problem leftover:

0 || 0 should giv 0 as result and not division by zero error. Cool



All the best,

Peter

[Updated on: Wed, 24 April 2019 13:02]

Report message to a moderator

Re: New package MathTools [message #51674 is a reply to message #51666] Wed, 24 April 2019 13:29 Go to previous messageGo to next message
peterh is currently offline  peterh
Messages: 46
Registered: November 2018
Location: Germany
Member
Results of stress-test:

1||0 = 0
0||0 Error Division by zero
-1||0 Error Division by zero
-1 || -1 Error Division by zero
1||1 = 0.5

If (arg1 * arg2) = 0 then the result is 0, else the result is arg1*arg2/(arg1+arg2). Rolling Eyes

And yes, there are negative resistors.

A negative resistor produces energy and gets cold when it does so. Very Happy
Unfortunately it is not available as discrete component. It stops working when it gets cold, that is the technological problem and causes resistor noise. Very Happy Very Happy
I am kidding Very Happy

To be serious:
For example the input impedance of an amplifier with positive feedback can be negative.

Negative resistors can exist in active circuits only as a mathemathik intermediate result.
This means only two complementary resistor values should lead to division by zero e.g. -1||1 = infinite resistance = division by zero.

[Updated on: Wed, 24 April 2019 17:59]

Report message to a moderator

Re: New package MathTools [message #51701 is a reply to message #51674] Sat, 27 April 2019 18:35 Go to previous messageGo to next message
peterh is currently offline  peterh
Messages: 46
Registered: November 2018
Location: Germany
Member
Hi Koldo,

I modified the calculation a little bit:

	void ResParallel(const doubleUnit &d) {
//		if (val + d.val < 1e-100)
//			throw Exc(t_("Division by zero"));
		if (!(unit.IsEqual(d.unit) || IsNull(unit) || IsNull(d.unit)))
			throw Exc(t_("Units does not match in resistor parallel"));
		if (abs(val*d.val) < 1e-100)
			val = 0.0;
		else
			if (abs(val + d.val) < 1e-100)
				throw Exc(t_("Division by zero"));
			val = val*d.val/(val + d.val);
	}	



It delivers now these results (which are correct):

1||1 = 0.5
1||0 = 0
0||0 = 0
-2||1 = 2
-1||2 = -2
-1||1 Error Division by zero

Please note, the "parallel" operator is not only useful for electronics.
There are many physic equations where this is useful.
For example, two elastic springs may have the elasticity konstants k1 and k2.

If the springs are in parallel then the total konstant is k1 + k2.
If the springs are in series then the total konstant is k1 || k2.

Some mathematicians might complain, that 0^2 / 0 = 0 is not allowed.
In physics this is allowed because the numbers have dimensions.

0^2 Ohm^2 is in a different dimension as 0^1 Ohm^1.
Ohm^2 and Ohm is as different as m^2 and m^1 and cannot been compared, added or subtracted.
The other point is: there is no absolute zero in physics, there is only zeropoint noise Wink

Therefore this calculation is perfectly legal in physics. Wink



Again, many thanks,

Peter






[Updated on: Sat, 27 April 2019 20:16]

Report message to a moderator

Re: New package MathTools [message #51702 is a reply to message #51701] Sat, 27 April 2019 22:12 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3121
Registered: August 2008
Ultimate Member
Thank you Peterh

It is now included.

Just for you to know, you can do this. If text is not detected as part of the expresion, it is considered a comment and it is indented to the right as indicated in "Tab chars"

index.php?t=getfile&id=5836&private=0
  • Attachment: Captura.JPG
    (Size: 34.26KB, Downloaded 116 times)


Best regards
Iñaki
Re: New package MathTools [message #51703 is a reply to message #51702] Mon, 29 April 2019 08:46 Go to previous message
peterh is currently offline  peterh
Messages: 46
Registered: November 2018
Location: Germany
Member
Thats a good feature.

Rp = Rx || R1
Rx is unknown. Follows:
Rx = Rp || -R1
Its now at my fingertips.
Thank you very much!

Previous Topic: PtyProcess, a pseudo-terminal process class for U++
Next Topic: MATLAB .mat files handling
Goto Forum:
  


Current Time: Sat May 30 08:21:54 CEST 2020

Total time taken to generate the page: 0.01754 seconds