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:
Calling Symbolic Variables from M-Files

Subject: Calling Symbolic Variables from M-Files

From: Dean

Date: 11 Nov, 2010 02:09:04

Message: 1 of 2

Hi,

Working in the command window, I have painstakingly created a very large symbolic expression F stored as a symbolic variable. F is a function of X and Z, where X and Z are 5-element symbolic vectors (X=[x1 x2 .... x5], Z={z1 z2 ... z5]). In addition, I have evaluated the symbolic gradient (GradF, a 5x1 vector) and Hessian (HessF, a 5x5 matrix) of F with respect to X. F is so large that it exceeds the maximum line limit of 25,000 characters, and in fact so does every element of the gradient and Hessian!

I now need to write an iterative program which calculates the values of F, as well as the gradient and Hessian of F at different values of X and Z. Is there a way to do this in an m-file without explicitly entering the formulae in the m-file (which would be nigh on impossible) or having to derive the formulae in the m-file (which is possible but would make for a very slow program). Can I substitue values of X and Z generated in the m-file program into the symbolic variables F, GradF and Hess F saved in the workspace?

Thanks for your help.
Dean

Subject: Calling Symbolic Variables from M-Files

From: Steven_Lord

Date: 11 Nov, 2010 14:53:30

Message: 2 of 2



"Dean " <dchesterfield@hotmail.com> wrote in message
news:ibfj80$b7c$1@fred.mathworks.com...
> Hi,
>
> Working in the command window, I have painstakingly created a very large
> symbolic expression F stored as a symbolic variable. F is a function of X
> and Z, where X and Z are 5-element symbolic vectors (X=[x1 x2 .... x5],
> Z={z1 z2 ... z5]). In addition, I have evaluated the symbolic gradient
> (GradF, a 5x1 vector) and Hessian (HessF, a 5x5 matrix) of F with respect
> to X. F is so large that it exceeds the maximum line limit of 25,000
> characters, and in fact so does every element of the gradient and Hessian!
>
> I now need to write an iterative program which calculates the values of F,
> as well as the gradient and Hessian of F at different values of X and Z.
> Is there a way to do this in an m-file without explicitly entering the
> formulae in the m-file (which would be nigh on impossible) or having to
> derive the formulae in the m-file (which is possible but would make for a
> very slow program). Can I substitue values of X and Z generated in the
> m-file program into the symbolic variables F, GradF and Hess F saved in
> the workspace?

Have you tried using matlabFunction to automate your first idea of entering
the formula in a function?

http://www.mathworks.com/help/toolbox/symbolic/matlabfunction.html

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with 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