Jump to content
Sign in to follow this  
Ivan

Symbolic function

Recommended Posts

Good day,

 

I'm new to Compose and i have some questions, i hope u can help me out. 

 

What is the equivalence for syms function (in Matlab) in Altair Compose? And how can I derivate symbolically in this software?

 

I'm testing this software and trying to get used to it, so i'm programming a simple Newton-Raphson method, this is the way i did it with matlab:


syms x 
fx=input('Enter the function: ')
dfx=diff(fx);
E=1; e=0.0001; i=1;
Ai=zeros(3,1); Axr=zeros(3,1); AE=zeros(3,1);
xo=input('Initial value:  ');
while E>e
    fxp=subs(fx,xo);
    dfxp=subs(dfx,xo);
    xr=xo-fxp/dfxp;
    E=abs((xr-xo)/xr);
    xo=xr;
    Ai(i)=i; Axr(i)=xr; AE(i)=E;
    i=i+1;
end
Res=[Ai Axr AE]

 

and here it is the way i did it with compose:

 

f=@(x) exp(-x)-x;   
df=@(x) -exp(-x)-1;
E=1; e=0.0001; i=1;
Ai=zeros(3,1); Ar=Ai; AE=Ai;
%xo=0;
xo=input('Initial value: ')
while E>e
    fxp=f(xo);
    dfxp=df(xo);
    xr=xo-fxp/dfxp;
    E=abs((xr-xo)/xr);
    xo=xr;
    Ai(i)=i; Ar(i)=xr; AE(i)=E;
    i=i+1;
end
Res=[Ai Ar AE]

 

The questions are as stated above, because I want to differentiate any simple function I give as input.

 

btw, sorry for broken english.

Share this post


Link to post
Share on other sites

Hi Ivan,

 

Unfortunately oml language doesn't support yet symbolic math.

 

You can try to leverage Python-bridges provided by Compose though.

 

Cheers,

 

Lorenzo

Ivan likes this

Share this post


Link to post
Share on other sites

Oh, I understand.

 

Thank you so much for the information, I'll look into this new option you mentioned.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×
×
  • Create New...