Got Questions? Get Answers.
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:
Embedded functions in "solve."

Subject: Embedded functions in "solve."

From: Armen

Date: 7 Jul, 2011 15:30:13

Message: 1 of 2

Hey everybody:

I'm rather new to matlab so I'm sure this question isn't too difficult to solve, so bear wtih me. I would like to solve a quartic equation for a single variable - straightforward enough. However, the coefficients of this quartic are themselves functions. The actual equations are rather complicated, so I'll post a simplified example:

solve('a*x^4 + a*b*x^3 + c*x^2 + d = 0', 'x');

where
a = 4*m^3;
b = 3*sqrt(a*n);
c = 16*m*n;
d = 5*n^2;

where m and n are user-defined inputs.

As I understand it, solve only works when the input terms are cast as symbolic variables. However, whenever I try to cast a, b, c, d, m, and n as symbolic variables, neither values nor functionality is preserved. My question is, what needs to be defined as a symoblic variable, or is there another way to do this?

Thanks for your help.

am

Subject: Embedded functions in "solve."

From: Steven_Lord

Date: 7 Jul, 2011 15:41:34

Message: 2 of 2



"Armen " <armen.melikian@gmail.com> wrote in message
news:iv4je5$aeg$1@newscl01ah.mathworks.com...
> Hey everybody:
>
> I'm rather new to matlab so I'm sure this question isn't too difficult to
> solve, so bear wtih me. I would like to solve a quartic equation for a
> single variable - straightforward enough. However, the coefficients of
> this quartic are themselves functions. The actual equations are rather
> complicated, so I'll post a simplified example:
>
> solve('a*x^4 + a*b*x^3 + c*x^2 + d = 0', 'x');

Don't call SOLVE with string inputs.

syms m n x % Use SYM instead if defining these in a function
a = 4*m^3;
b = 3*sqrt(a*n);
c = 16*m*n;
d = 5*n^2;
S = solve(a*x^4+a*b*x^3+c*x^2+d, x);

Or if you have numeric values for m and n:

m = 1;
n = 2;
syms x % Use SYM instead if defining this in a function
a = 4*m^3;
b = 3*sqrt(a*n);
c = 16*m*n;
d = 5*n^2;
S = solve(a*x^4+a*b*x^3+c*x^2+d, x);

--
Steve Lord
slord@mathworks.com
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