kill(all)$

Maxima temperature Antione eq (Solve Nonlinear Equation)
peter.vlasschaert@gmail.com,13/08/2020

math : Newton-Raphson (single variable ,f(x))
===================================

math: f(x) = 0
---------------------------------------------------------------------------------
?  x[i]  =  i values  ( all x values)
To find  x   = >  f(x) = 0
x[i+1] = x[i] - f(x)/df(x)  , see : 'algorithm' below,updated → cvg
---------------------------------------------------------------------------------
→ df(x)  = differentation of f(x) with respect to  x
---------------------------------------------------------------------------------

package :,option.
============

load(lrats)$
ratprint:false;

Formule : Antione Equation.(Mixture)
===========================
→  spreadsheet : EXP ; Maxima : exp

p1:B2*exp(C2-D2/(B6+E2))+B3*exp(C3-D3/(B6+E3));

used : truebasic :
Function df(m,m11,m21,m31,m41,m12,m22,m32,m42,p1)

p1c:diff(p1-p,B6);

recover : from spreadsheet

1e)  component : (of the Mixture)
----------------------
physical :{C2,D2,E2}

B2:0.9337;/*mole fraction*/
C2:14.3916;
D2:2795.82;
E2:230;

p1a:ev(p1,nouns),numer;

2e)  component : ( of the Mixture)
----------------------
physical :{C3,D3,E3}

B3:1-B2;/*mole fraction*/
C3:16.262;
D3:3799.89;
E3:226.25;

p1b:ev(p1,nouns),numer;

P:101.325; /*total pressure*/;

FORMULA :
========

p2:p1-P;

find : B6 ( = temperature [°C] )

p3:ev(p2,nouns)=0;

p31a:lhs(p3);

T guess:B6 = 60

p3a:lratsubst([B6=60],p3),float;

special :packages ' solve nonlinear equations:p3'
===================================

→  Maxima Packages :

load("mnewton")$

 mnewton([p3],
              [B6], [55])[1];

check :

p3b:lratsubst(%,p3),numer;

Newton Raphson method : single variable
=============================
do while :structure

function : var = B6
--------------------------

p4a:f[B6]:=''p31a;

→  start value : Newton Raphson

p4a1:f[60];

derivativ function : var=B6
----------------------------------

p4b:df[B6]:=''diff(p31a,B6);

df[B6];

value for 'error control' of the solution
------------------------------------------------

eps :0.001;

algorithm
------------

mynewton[expr,var,st,eps]:=block(    
    df:diff(expr,var),m:st,
  while abs(lratsubst([var= m],expr)) > eps 
    do(
    r:lratsubst([var=m],expr)/lratsubst([var=m],df),        
    m:m-lratsubst([var=m],r)    
       ),      
   return(m) 
)$

rem : always do evaluation of the expression when you want, numerical value.
use here : lratsubst , from packages  'lrats'.

→  optimized :code

grind(mynewton)$

p4c:mynewton[p31a,B6,60,eps],float;

check value :with definition (= 'p4a')
----------------------------------------------
root = p4c, solution : 'p4a'

p4d:f[p4c];

draw graphics : 'p31a' , around : B6 = 60.
==============================

wxplot2d([p31a], [B6,50,70])$

wxplot2d([p31a], [B6,55,60])$