Author Topic: Math issue  (Read 3971 times)

zckumling

Math issue
« on: April 11, 2010, 06:44:33 PM »
Hi, I'm not sure if this is the right place to post this problem..
I'm doing some analog simulation (DSP) and I'm trying to use Newton Method to solve an iterative problem.

x(n+1) = x(n) - f(x)/f'(x)

From KCL my function is:
(Vout-Vaa)/Ra + Vout/Rload + f(Vgk, Vout) = 0

where f(Vgk, Vout) is a lookup table function to get the (nonlinear) anode current ( 'Ia' ) of a triode.

my problem is to differentiate this function, the derivate yields:
   d
------ f(Vgk, Vout) + 1/Rload +1/Ra
d Vout

which I understand as:
(Ia(n) - Ia(n-1)) / (Vout(n)-Vout(n-1)) + 1/Rload + 1/Ra

but it doesn't converge .. have I misunderstood it ? I have a reasonable first guess x(n)

slotbot

Re: Math issue
« Reply #1 on: April 11, 2010, 08:02:59 PM »
if you need n-1 for the first iteration how do you compute it?

i don't know if thats clear but like. first iteration x(n) is your guess right? and then f(x) you can find but then how are you computing the denominator (f'(x)) without knowing Ia(n-1)?

are you using a computer to iterate? maybe this is why it isnt converging?


edit... also i dont know what your constraints are but you could just dump the lookup table into excel and have it approximate the nonlinear function. Then just use that instead.
« Last Edit: April 11, 2010, 08:06:44 PM by slotbot »

PRR

Re: Math issue
« Reply #2 on: April 11, 2010, 11:44:53 PM »
> if you need n-1 for the first iteration how do you compute it?

zckumling said "I have a reasonable first guess x(n)".

That's all which is needed. It does not have to be a "good" guess, just not too very far wrong. For a tube circuit, "0.5 times supply" or "+150V" will get the iteration started.

How would you find the square-root of 7? Without a calculator, slide-rule, or framing-square?

Guess, check, note high/low, guess again. Repeat until close-enuff.

7 is a small number so its SR is probably a small number?

2^2= 4, too low.
3^2= 9, too high. But closer than 4.
Be stupid. Split the difference. 2.5^2= 6.25.
Pick a number closer to 3 than to 2.
2.6^2= 6.76. Getting closer.
2.7^2= 7.29. Close but over-shot.
2.65^2= 7.0225, which may be close enough for any practical purpose.
If more accuracy is wanted, try 2.645^2= 6.996.. which is very close.

Six easy steps found square-root of 7 within 0.06%.

zckumling wants a result equal to his successive guess.

In a tube circuit where the answer is really 200V, a first-guess of "150" would give a result of 180, wrong. A next-guess of 180 might give 190. Guessing 190 might give 199. And in tube-work, 199 is exactly equal to 200 because all self-biased tube-work is 10% precision at best. Even with a pretty-bad starting-guess like 50V, it should take very few iterations to get a result with better "accuracy" than the tubes we use.

> it doesn't converge

I can think-about math, but I can't DO math. So I don't know.

However triodes are not that non-linear. It should converge within 10% in very few steps; else you have lost a negative-sign or multiplied where you should divide. I suggest you print the first half-dozen iterations for a "known" circuit, and see if the numbers go toward the known answer or head off in the wrong direction. The size and direction of deviation may suggest where your formula is incorrect.

ARON: this could perhaps be moved to Stimulation section. zckumling is doing simulation, just not with a for-purpose simulator. Some of the sim-wizards there may know where zckumling has gone wrong.
  • SUPPORTER

slotbot

Re: Math issue
« Reply #3 on: April 12, 2010, 12:09:37 AM »
> if you need n-1 for the first iteration how do you compute it?

zckumling said "I have a reasonable first guess x(n)".

That's all which is needed. It does not have to be a "good" guess, just not too very far wrong. For a tube circuit, "0.5 times supply" or "+150V" will get the iteration started.

How would you find the square-root of 7? Without a calculator, slide-rule, or framing-square?

Guess, check, note high/low, guess again. Repeat until close-enuff.

7 is a small number so its SR is probably a small number?

2^2= 4, too low.
3^2= 9, too high. But closer than 4.
Be stupid. Split the difference. 2.5^2= 6.25.
Pick a number closer to 3 than to 2.
2.6^2= 6.76. Getting closer.
2.7^2= 7.29. Close but over-shot.
2.65^2= 7.0225, which may be close enough for any practical purpose.
If more accuracy is wanted, try 2.645^2= 6.996.. which is very close.

Six easy steps found square-root of 7 within 0.06%.

zckumling wants a result equal to his successive guess.



yes i get all this.

but if you look at the LHS of the original equation hes calculating iteration n+1 from his guess n. thats ok. now look at the RHS he has  f'(x) and then later suggests f'(x) requires the value Ia(n-1) which he wont have, even with a good guess (ie what was the value of the current the iteration before i guessed?). that was more my point. not that he dosnt have x(n).

Also if the triode is not that non linear as you say, it might just be easier to approximate the function as a 2nd, 3rd or 4th order polynomial because taking the derivative of a polynomial is not very difficult. (then you would not need the previous value).

I think everything is ok except how he is formulating the derivative?

« Last Edit: April 12, 2010, 01:32:48 AM by slotbot »

zckumling

Re: Math issue
« Reply #4 on: April 12, 2010, 06:36:57 AM »
Thanks for the replies so far!

I've wrote something wrong in my first post. the function f(vgk, vout) is not a lookup table, it's the koren equations for triode plate current.
I precalculate the anode current over a given loadline/Vgk values.. so for each iteration, vgk is the parameter which is sweeped from "Ia_max"(vaa/ra) to cutoff,
I then approximate the plate voltage for each value of vgk with this iteration, and saves the plate current to a lookup-table which I then use to run a realtime oversampled simulation.

In other words,
vk = set to 0.0 volt ;
f(vg-vk, vout-vk) = f(vgk, vout) = function to run the koren equations..

I'm not sure if I should include those equations in my KCL function instead of f(vgk, vout) and maybe get a better derivative.. ? It might get too complex ..

zckumling

Re: Math issue
« Reply #5 on: April 12, 2010, 11:09:34 AM »
By the way.. are there any iteration schemes that are usable when it comes to iterate over a function expressed as:
vout = (Ia_max - f(vgk, vout)) * Zout

I'm not used to this problems :P

slotbot

Re: Math issue
« Reply #6 on: April 12, 2010, 11:47:15 AM »
you could look up "fixed point" method. basically it follows the form

x_n+1 = f(x_n)

so like the newton method you need a first guess. in this method the guess is more critical in terms of convergence.

so in your case you have

vout_n+1 = (Ia_max - f(vgk, vout_n)) * Zout

i use the  _ to mean subscript.

zckumling

Re: Math issue
« Reply #7 on: April 12, 2010, 01:04:16 PM »
Thank you! It helped  ;)

QSQCaito

  • Awesome!
  • ****
  • Posts: 862
  • Total likes: 1
  • Diego Andrés. Buenos Aires, Argentina.
Re: Math issue
« Reply #8 on: April 23, 2010, 07:53:43 PM »
There's another method.

if f(a)*f(b) < 0

then between a and b, there's a point c such that f(c)=0

you take the interval [a;c]

f(c)==0?

if f(a)*f(c)< 0
then it's between a and c

else
it is between c and b.



repeat this as many times as you wish.



You could also use fixed point, but again, you need many more conditions in order for it to converge.

Newton raphson is the best if you have to do this hundreds of times. But, in the scale you are working, i don't believe it is necessary.




Bye!


PS
D.A.C