From: Patricio on
Hi,
I hope somebody can help with the following problem: I have a procedure that works well in MuPad, but then, when I call it in MATLAB, i simply cannot get it to work well. Here are the details:

This is the procedure that works well in MuPad for a function f and numbers a and b:
proc(f, a, b)
name rango;
local X, F;
begin
X := hull(a, b);
F := subs(f, x = X);
op(hull(F), 2)
end_proc

I then call it from MATLAB using the following M-file:
% TEST DE RANGO
clc
clear all
syms x
a=0;
b=1.2;
f=(1.4-3*x)*sin(18*x);
r=feval(symengine,'rango',f,a,b)

but get the following result:

r =
rango(-sin(18*x)*(3*x - 7/5), 0, 6/5)

while, what I should get in reality is r=0. Does anyone know what is the right way to proceed in order to obtain the correct result r=0 in MATLAB?

Thanks in advance for your help.

Patricio Basso.
From: Patricio on
"Patricio " <patricio.basso(a)gmail.com> wrote in message <hrch68$k65$1(a)fred.mathworks.com>...
> Hi,
> I hope somebody can help with the following problem: I have a procedure that works well in MuPad, but then, when I call it in MATLAB, i simply cannot get it to work well. Here are the details:
>
> This is the procedure that works well in MuPad for a function f and numbers a and b:
> proc(f, a, b)
> name rango;
> local X, F;
> begin
> X := hull(a, b);
> F := subs(f, x = X);
> op(hull(F), 2)
> end_proc
>
> I then call it from MATLAB using the following M-file:
> % TEST DE RANGO
> clc
> clear all
> syms x
> a=0;
> b=1.2;
> f=(1.4-3*x)*sin(18*x);
> r=feval(symengine,'rango',f,a,b)
>
> but get the following result:
>
> r =
> rango(-sin(18*x)*(3*x - 7/5), 0, 6/5)
>
> while, what I should get in reality is r=0. Does anyone know what is the right way to proceed in order to obtain the correct result r=0 in MATLAB?
>
> Thanks in advance for your help.
>
> Patricio Basso.

Hi,
I made a mistake in my last message. For the above example the correct value is r = 2.2. The value r = 0 corresponds to the function f: =- x ^ 2.

Sorry,

Patricio Basso
From: Alan Weiss on
"Patricio " <patricio.basso(a)gmail.com> wrote in message <hret2g$o86$1(a)fred.mathworks.com>...
> "Patricio " <patricio.basso(a)gmail.com> wrote in message <hrch68$k65$1(a)fred.mathworks.com>...
> > Hi,
> > I hope somebody can help with the following problem: I have a procedure that works well in MuPad, but then, when I call it in MATLAB, i simply cannot get it to work well. Here are the details:
> >
> > This is the procedure that works well in MuPad for a function f and numbers a and b:
> > proc(f, a, b)
> > name rango;
> > local X, F;
> > begin
> > X := hull(a, b);
> > F := subs(f, x = X);
> > op(hull(F), 2)
> > end_proc
> >
> > I then call it from MATLAB using the following M-file:
> > % TEST DE RANGO
> > clc
> > clear all
> > syms x
> > a=0;
> > b=1.2;
> > f=(1.4-3*x)*sin(18*x);
> > r=feval(symengine,'rango',f,a,b)
> >
> > but get the following result:
> >
> > r =
> > rango(-sin(18*x)*(3*x - 7/5), 0, 6/5)
> >
> > while, what I should get in reality is r=0. Does anyone know what is the right way to proceed in order to obtain the correct result r=0 in MATLAB?
> >
> > Thanks in advance for your help.
> >
> > Patricio Basso.
>
> Hi,
> I made a mistake in my last message. For the above example the correct value is r = 2.2. The value r = 0 corresponds to the function f: =- x ^ 2.
>
> Sorry,
>
> Patricio Basso

The following technique might work:

Store the procedure in a file, say rango.mu. Then run
eng=symengine;
eng.feval('read','path to file rango.mu');
eng.feval('rango',&#8230;) % just like your first attempt

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation
From: Svetlana on
Hi Patricio,

First, assign a procedure to any identifier (name). For example, rango := proc(f, a, b). This way you will be able to call the procedure. The &#8216;name rango&#8217; line only affects the outputs, it does not allow to call the procedure.

rango := proc(f, a, b)
local X, F;
begin
X := hull(a, b);
F := subs(f, x = X);
op(hull(F), 2)
end_proc

Then, save a procedure to a file - for example, as rango.mu in C:/MuPAD.

In MATLAB, execute the following commands. The only difference with what Alan has suggested is about quotes. Use two pairs of qoutes for the file path (double quotes should be inside single quotes):
syms x
a=0;
b=1.2;
f=(1.4-3*x)*sin(18*x);
eng=symengine;
eng.feval('read',' "C:/MuPAD/rango.mu" ');
eng.feval('rango',f,a,b)

I hope that helps!

Svetlana Eliseeva
Technical Writer
MathWorks Documentation Group
From: Patricio on
"Svetlana " <svetlana.eliseeva(a)mathworks.com> wrote in message <hrpjha$9a7$1(a)fred.mathworks.com>...
> Hi Patricio,
>
> First, assign a procedure to any identifier (name). For example, rango := proc(f, a, b). This way you will be able to call the procedure. The &#8216;name rango&#8217; line only affects the outputs, it does not allow to call the procedure.
>
> rango := proc(f, a, b)
> local X, F;
> begin
> X := hull(a, b);
> F := subs(f, x = X);
> op(hull(F), 2)
> end_proc

Hi Svetlana,

It works!. Thank to you and Alan.

Muchas gracias amigos,

Patricio


>
> Then, save a procedure to a file - for example, as rango.mu in C:/MuPAD.
>
> In MATLAB, execute the following commands. The only difference with what Alan has suggested is about quotes. Use two pairs of qoutes for the file path (double quotes should be inside single quotes):
> syms x
> a=0;
> b=1.2;
> f=(1.4-3*x)*sin(18*x);
> eng=symengine;
> eng.feval('read',' "C:/MuPAD/rango.mu" ');
> eng.feval('rango',f,a,b)
>
> I hope that helps!
>
> Svetlana Eliseeva
> Technical Writer
> MathWorks Documentation Group