Message Boards Message Boards

0
|
4105 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Wrong result in mathematical model

Posted 9 years ago

I am a retired Electrical engineer, I have coded a model of a full wave rectified power supply. I have been using the model in Mathematica and Matlab.

The results are very close to what is expected with the Matlab model. However, Mathematica is giving the result for variable "BleederDischTime" off by a factor of 10^6 power. The equations are identical in the Mathematica model and the Matlab model. They were cut and pasted from Matlab to Mathematica. With proper fixing up of function brackets and equal signs of course. This truly appears to be a mathematica "bug" to me. I have to divide the "BleederDischTime" result, in Mathematica by 10^6 to get the same result Matlab gives without the same division. What is interesting is that I use a factor 0f 10^6 to convert Farads to Microfarads after the calculations are done for output. It seems unrelated to the "wrong result" described above. What could be going on here? I will post the Mathematica and identical Matlab files here. Thank you all!

Attachments:
POSTED BY: Kent J Jarvis
4 Replies
Posted 9 years ago

Ok, to be specific, I think I see now exactly what happened.

The way you defined things, when you do

BleederDichTime := ....

The value of CValue is one thing.

Then just a bit later, you change CValue (multiply it by 1000000).

Then, later, you print out BleederDichTime, and it evaluates the expression with the NEW value of CValue.

So everything is acting precisely as it should...

POSTED BY: Todd Moyer
Posted 9 years ago

Ok Todd, I get it. I need to be careful of delayed referencing.

I am in my 70s now, but this is a model of an amateur radio power supply I built from an article in a Amateur radio magazine back in 1957. It had 2 866a Mercury vapor rectifier tubes. I got rather severely shocked, when as I was measuring the output voltage with a vacuum tube voltmeter. I was pulling the grounded aluminum chassis closer to me with my left hand, while holding the voltmeter probe tip on the supply output with my right hand. Unknown to me, the set screw holding the coaxial cable in to the probe tube had been screwed down too tight, and was in contact with the coax center conductor going to the probe tip.. My left hand was on ground, and my right was gripping the probe and the set screw. I woke up across the room, on the other side of the bed. My back muscles hurt for about 8 months. They were part of the current flow. Always use only 1 hand when working with high voltage. So I became an Electrical Engineer. This model seems to work on low semiconductor voltages also. The filter capacitors are much larger, and a bleeder resistor is not needed.

Kent

POSTED BY: Kent J Jarvis
Posted 9 years ago

Oh good grief. I changed the := to = on the variable "BleederDischTime", and the problem went away. I have been having all kinds of problems with = vs := . I initially thought that if the value of a variable was going to change, such as in a loop, that just = made it work := caused something recursive to happen. Sometimes changing it made it worse. Anyway thanks for the tip. I just decided to try on the affected variable, and it works.

Sincerly, Kent

POSTED BY: Kent J Jarvis
Posted 9 years ago

Hi Kent, another EE here... Always glad to see more Mathematica users! I have not parsed your code fully yet, but I did quickly notice that you have an odd, or non-standard, mixing of "=" and ":=".

At least to begin, a simple rule, not hard and fast, but pretty much applies in most cases:

":=" is used when defining a function, and not for much else.

Its precise meaning is that the expression with ":=" is not evaluated until it is referenced, whereas "=" evaluates immediately. I've had some weird things happen when I use ":=" similar to the way you have.

From what I can tell, you can go through your code and replace all the ":=" with "=" as a quick test, and see if that makes a difference in your answer.

Regards, --Todd

POSTED BY: Todd Moyer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract