Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Evaluating a called function from mupad in matlab script

Subject: Evaluating a called function from mupad in matlab script

From: SAONI

Date: 11 Jul, 2014 14:13:11

Message: 1 of 5

Hi,

I have evaluated a function in mupad and wish to call it in my matlab script. I use evalin in the script for evaluation of the expression. It goes like:

 t = evalin(symengine,'[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2)) + m^2 + n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) + m^2 + n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 .. infinity)]')


Now since, '[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2)) + m^2 + n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) + m^2 + n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 .. infinity)]' is a string and is evaluated from mupad, it does not take in the values declared to the variables : tou, sigma, chi, Pa,w,h and L from the matlab function file. I could declare the values to these variables in mupad and evaluate the given expression in the function file but it is not convenient since I have to go to mupad to change the values of the variable every time and cannot directly change it from the command line.

My question is ..Could I concatenate the strings individually in the function file for the given expression '[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2)) + m^2 + n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) + m^2 + n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 .. infinity)]' and the above mentioned values could take the values declared in the function file or directly from the command line ?

Subject: Evaluating a called function from mupad in matlab script

From: Steven Lord

Date: 11 Jul, 2014 15:09:06

Message: 2 of 5


"SAONI " <bsaoni@gmail.com> wrote in message
news:lpordn$ok1$1@newscl01ah.mathworks.com...
> Hi,
>
> I have evaluated a function in mupad and wish to call it in my matlab
> script. I use evalin in the script for evaluation of the expression. It
> goes like:
>
> t =
> evalin(symengine,'[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2))
> + m^2 + n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) +
> m^2 + n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 ..
> infinity)]')
>
>
> Now since, '[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2))
> + m^2 + n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) +
> m^2 + n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 ..
> infinity)]' is a string and is evaluated from mupad, it does not take in
> the values declared to the variables : tou, sigma, chi, Pa,w,h and L from
> the matlab function file. I could declare the values to these variables in
> mupad and evaluate the given expression in the function file but it is not
> convenient since I have to go to mupad to change the values of the
> variable every time and cannot directly change it from the command line.
>
> My question is ..Could I concatenate the strings individually in the
> function file for the given expression
> '[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2)) + m^2 +
> n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) + m^2 +
> n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 .. infinity)]' and
> the above mentioned values could take the values declared in the function
> file or directly from the command line ?

I don't see anything in that expression that requires you to execute it in
MuPAD. I'd probably use SYMSUM instead:

http://www.mathworks.com/help/symbolic/symsum.html

If there's a specific piece that you need to evaluate in MuPAD, the
expression you pass into SYMSUM can use evalin(symengine, ...) as far as I
am aware.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Evaluating a called function from mupad in matlab script

From: BS

Date: 11 Jul, 2014 15:57:18

Message: 3 of 5

Hi,

Since this is a large expression, matlab is unable to compute the entire expression from 1 to infinity, and displays the answer in the form mentioned underneath: (includes complex numbers)

MATLAB:

syms m n
>> t = symsum(symsum((0.193 + m^2 + n^2)/((m*n)^2*((0.193 + m^2 + n^2)*(0.193 + m^2 + n^2) + 0.12)), m, 1, Inf ), n, 1, Inf)

t
(500*sum((30349057*pi^2 - 12379500*psi((- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) + 579000000*psi((- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(3/2) + 579000000*psi((- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(3/2) - 12379500*psi((- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 231747000*pi^2*n^2 + 579000000*pi^2*n^4 + 1000000000*pi^2*n^6 + 12379500*psi(1 - (- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 12379500*psi(1 - (- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) - 579000000*psi(1 - (- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(3/2) - 579000000*psi(1 - (- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 + (3^(1/2)*i)/5 -
193/1000)^(3/2) + 1737000000*n^2*psi((- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1737000000*n^2*psi((- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) + 3000000000*n^2*psi((- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(3/2) + 3000000000*n^2*psi((- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(3/2) + 4500000000*n^4*psi((- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) + 4500000000*n^4*psi((- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) + 1)*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) - 1737000000*n^2*psi(1 - (- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) - 1737000000*n^2*psi(1 - (- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2) -
3000000000*n^2*psi(1 - (- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(3/2) - 3000000000*n^2*psi(1 - (- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(3/2) - 4500000000*n^4*psi(1 - (- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 - (3^(1/2)*i)/5 - 193/1000)^(1/2) - 4500000000*n^4*psi(1 - (- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2))*(- n^2 + (3^(1/2)*i)/5 - 193/1000)^(1/2))/(n^2*(1000000*n^4 + 386000*n^2 + 157249)^2), n = 1..Inf))/3
 

which does not give me the exact value while when I evaluate the same expression in mupad:


t = sum(sum(((0.193 + m^2 + n^2))/((m*n)^2*((0.193 + m^2 + n^2)*(0.193 + m^2 + n^2) + 0.12)), m = 1 .. infinity), n = 1 .. infinity)

t =0.5942218128


Any help would be appreciated.

Thanks,
SB







"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lpoun7$4pc$1@newscl01ah.mathworks.com>...
>
> "SAONI " <bsaoni@gmail.com> wrote in message
> news:lpordn$ok1$1@newscl01ah.mathworks.com...
> > Hi,
> >
> > I have evaluated a function in mupad and wish to call it in my matlab
> > script. I use evalin in the script for evaluation of the expression. It
> > goes like:
> >
> > t =
> > evalin(symengine,'[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2))
> > + m^2 + n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) +
> > m^2 + n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 ..
> > infinity)]')
> >
> >
> > Now since, '[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2))
> > + m^2 + n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) +
> > m^2 + n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 ..
> > infinity)]' is a string and is evaluated from mupad, it does not take in
> > the values declared to the variables : tou, sigma, chi, Pa,w,h and L from
> > the matlab function file. I could declare the values to these variables in
> > mupad and evaluate the given expression in the function file but it is not
> > convenient since I have to go to mupad to change the values of the
> > variable every time and cannot directly change it from the command line.
> >
> > My question is ..Could I concatenate the strings individually in the
> > function file for the given expression
> > '[(16*sigma*Pa*chi*(L^2)/(pi^6)*w*h)*sum(sum(((((tou^2)/(pi^2)) + m^2 +
> > n^2))/((m*n)^2*((((tou^2)/(pi^2)) + m^2 + n^2)*(((tou^2)/(pi^2)) + m^2 +
> > n^2) + ((sigma^2)/(pi^4)))), m = 1 .. infinity), n = 1 .. infinity)]' and
> > the above mentioned values could take the values declared in the function
> > file or directly from the command line ?
>
> I don't see anything in that expression that requires you to execute it in
> MuPAD. I'd probably use SYMSUM instead:
>
> http://www.mathworks.com/help/symbolic/symsum.html
>
> If there's a specific piece that you need to evaluate in MuPAD, the
> expression you pass into SYMSUM can use evalin(symengine, ...) as far as I
> am aware.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Evaluating a called function from mupad in matlab script

From: Steven Lord

Date: 11 Jul, 2014 17:27:16

Message: 4 of 5


"BS " <bsaoni@gmail.com> wrote in message
news:lpp1gu$cc9$1@newscl01ah.mathworks.com...
> Hi,
>
> Since this is a large expression, matlab is unable to compute the entire
> expression from 1 to infinity, and displays the answer in the form
> mentioned underneath: (includes complex numbers)
>
> MATLAB:
>
> syms m n
>>> t = symsum(symsum((0.193 + m^2 + n^2)/((m*n)^2*((0.193 + m^2 +
>>> n^2)*(0.193 + m^2 + n^2) + 0.12)), m, 1, Inf ), n, 1, Inf)
>
> t

*snip large result*

> which does not give me the exact value while when I evaluate the same
> expression in mupad:
>
> t = sum(sum(((0.193 + m^2 + n^2))/((m*n)^2*((0.193 + m^2 + n^2)*(0.193 +
> m^2 + n^2) + 0.12)), m = 1 .. infinity), n = 1 .. infinity)
>
> t =0.5942218128

Tell MATLAB to use variable precision arithmetic to display it or to convert
it into a double array.

vpa(t, 10)
double(t)

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Evaluating a called function from mupad in matlab script

From: BS

Date: 11 Jul, 2014 20:26:18

Message: 5 of 5

Hi Steven,

Thanks a ton for the help. The solution is so simple and I didnĀ“t realize .

Thanking you,

SB

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lpp6qa$qho$1@newscl01ah.mathworks.com>...
>
> "BS " <bsaoni@gmail.com> wrote in message
> news:lpp1gu$cc9$1@newscl01ah.mathworks.com...
> > Hi,
> >
> > Since this is a large expression, matlab is unable to compute the entire
> > expression from 1 to infinity, and displays the answer in the form
> > mentioned underneath: (includes complex numbers)
> >
> > MATLAB:
> >
> > syms m n
> >>> t = symsum(symsum((0.193 + m^2 + n^2)/((m*n)^2*((0.193 + m^2 +
> >>> n^2)*(0.193 + m^2 + n^2) + 0.12)), m, 1, Inf ), n, 1, Inf)
> >
> > t
>
> *snip large result*
>
> > which does not give me the exact value while when I evaluate the same
> > expression in mupad:
> >
> > t = sum(sum(((0.193 + m^2 + n^2))/((m*n)^2*((0.193 + m^2 + n^2)*(0.193 +
> > m^2 + n^2) + 0.12)), m = 1 .. infinity), n = 1 .. infinity)
> >
> > t =0.5942218128
>
> Tell MATLAB to use variable precision arithmetic to display it or to convert
> it into a double array.
>
> vpa(t, 10)
> double(t)
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us