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:
Solving for unknowns using symbolic variable

Subject: Solving for unknowns using symbolic variable

From: Triton Squad

Date: 12 Nov, 2012 20:40:21

Message: 1 of 3

Hello all,

So I've been stuck at a rather problem for hours now and I'm not going anywhere so I was hoping somebody could help me.

I have a set of equations in which I have to solve for an unknown variable q0, and it goes as follows!

% first set of equations
syms q0

q1 = q0
q2 = q1 + x1
q3 = q2 + x2
.
.
.
q(i) = q(i-1) + x(i-1)

In this equation, {x} is known so the only unknown is q0

In my second set of equations, the sum of q(i)*constants = 0, meaning

% second equation
(q1*y1)+(q2*y2)+(q3*y3)+...+(q(i)*yi) = 0

In this equation, again we only have the q0 as unknown. If I were to do it by hand I would just multiply equation 2 through in terms of q0 and solve for q0 to get q1, q2 and so on.

But I am having a difficult time implementing this in matlab. Could someone help me please??

Subject: Solving for unknowns using symbolic variable

From: Alan_Weiss

Date: 12 Nov, 2012 21:02:37

Message: 2 of 3

On 11/12/2012 3:40 PM, Triton Squad wrote:
> Hello all,
>
> So I've been stuck at a rather problem for hours now and I'm not going
> anywhere so I was hoping somebody could help me.
>
> I have a set of equations in which I have to solve for an unknown
> variable q0, and it goes as follows!
>
> % first set of equations
> syms q0
>
> q1 = q0
> q2 = q1 + x1
> q3 = q2 + x2
> .
> .
> .
> q(i) = q(i-1) + x(i-1)
>
> In this equation, {x} is known so the only unknown is q0
>
> In my second set of equations, the sum of q(i)*constants = 0, meaning
>
> % second equation
> (q1*y1)+(q2*y2)+(q3*y3)+...+(q(i)*yi) = 0
>
> In this equation, again we only have the q0 as unknown. If I were to
> do it by hand I would just multiply equation 2 through in terms of q0
> and solve for q0 to get q1, q2 and so on.
>
> But I am having a difficult time implementing this in matlab. Could
> someone help me please??

Must you do it symbolically? If you are satisfied with a numeric
solution, fzero should be all you need. Write a function f implementing
all your equations in terms of the variable qo, so

f(q0) = (q1*y1)+(q2*y2)+(q3*y3)+...+(q(i)*yi)

where the program for f takes in all the x and y values. Then set

q0solution = fzero(@f)

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Solving for unknowns using symbolic variable

From: Roger Stafford

Date: 13 Nov, 2012 14:22:09

Message: 3 of 3

"Triton Squad" wrote in message <k7rmrl$cft$1@newscl01ah.mathworks.com>...
> I have a set of equations in which I have to solve for an unknown variable q0, and it goes as follows!
> .......
> But I am having a difficult time implementing this in matlab. Could someone help me please??
- - - - - - - - - -
  If for any (reasonably small) finite i you are careful to declare all symbols involved, the q's, x's, and y's, as symbolic, indicate which are the unknowns, (q0, q1, ..., qi,) and include all i+1 linear equations, then the 'solve' function of the symbolic toolbox will give you a solution for all the q's including q0.

  However, it is not able to obtain a general formula for q0 that holds for all i. That you would have to deduce from such results yourself after doing this for several representative values of i. (There is still a need for us mere mortals in this fast-moving computer world.)

Roger Stafford

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