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:
defining equations

Subject: defining equations

From: samira

Date: 29 Jun, 2011 18:01:10

Message: 1 of 3

Hi

I would like to use solve for solving nonlinear equations like this:

one=sym('(x-1)^2-(y-1)^2=0.5^2')
two=sym('(x-1.5)^2-(y-1)^2=0.5^2')
[x,y]=solve(one,two)

I want to make a function for that, so by giving different constants I can get different results.
Can you help me to see how can I store constants in above code in a matrix (like [1 1 0.5; 1.5 1 0.5;]) and use matrix arrays in defining my equations?

Thanks

Subject: defining equations

From: Steven_Lord

Date: 30 Jun, 2011 13:37:36

Message: 2 of 3



"samira " <samira.rashidi@gmail.com> wrote in message
news:iufp95$jac$1@newscl01ah.mathworks.com...
> Hi
> I would like to use solve for solving nonlinear equations like this:
>
> one=sym('(x-1)^2-(y-1)^2=0.5^2')
> two=sym('(x-1.5)^2-(y-1)^2=0.5^2')
> [x,y]=solve(one,two)
>
> I want to make a function for that, so by giving different constants I can
> get different results.
> Can you help me to see how can I store constants in above code in a matrix
> (like [1 1 0.5; 1.5 1 0.5;]) and use matrix arrays in defining my
> equations?

Don't define your equations as strings.

x = sym('x');
y = sym('y');
r1 = 0.5;
r2 = 0.5;
one = (x-1)^2-(y-1)^2-r1^2;
two = (x-1.5)^2-(y-1)^2-r2^2;
S = solve(one, two)

If you must define your equations as strings, use SUBS before calling SOLVE.

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

Subject: defining equations

From: Roger Stafford

Date: 30 Jun, 2011 17:47:09

Message: 3 of 3

"samira" wrote in message <iufp95$jac$1@newscl01ah.mathworks.com>...
> Hi
>
> I would like to use solve for solving nonlinear equations like this:
>
> one=sym('(x-1)^2-(y-1)^2=0.5^2')
> two=sym('(x-1.5)^2-(y-1)^2=0.5^2')
> [x,y]=solve(one,two)
>
> I want to make a function for that, so by giving different constants I can get different results.
> Can you help me to see how can I store constants in above code in a matrix (like [1 1 0.5; 1.5 1 0.5;]) and use matrix arrays in defining my equations?
>
> Thanks
- - - - - - - - - -
  When I used 'solve' on your problem, the answer it gave was much too long and complicated for my tastes, so I worked out a simpler procedure for you.

  To solve the equations

 (x-a)^2 - (y-b)^2 = c^2
 (x-d)^2 - (y-e)^2 = f^2

for arbitrary constants a, b, c, d, e, and f, do this:

 ad = a-d; be = b-e; adbe = ad^2-be^2;
 h = sqrt((adbe-c^2-f^2)^2-4*c^2*f^2);
 xf = (a+d)/2-ad*(c^2-f^2)/(2*adbe); xr = be*h/(2*adbe);
 yf = (b+e)/2-be*(c^2-f^2)/(2*adbe); yr = ad*h/(2*adbe);
 x1 = xf+xr; y1 = yf+yr;
 x2 = xf-xr; y2 = yf-yr;

Then the pair (x1,y1) will be one solution and (x2,y2) another. Note that some of the solutions will be complex-valued.

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