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:
Matlab function solving

Subject: Matlab function solving

From: Mikey Evans

Date: 20 Aug, 2013 14:20:25

Message: 1 of 3

Hello!

I'm having a bit of a problem with something that I thought would be simple:

I'd like to solve a function
 z = -out + x/1000*((0.88 + 0.437*incoming)*(2753.9 + 1.493*incoming) + (0.89 + 0.132*incoming)*(2651.1 + 0.984*incoming));

where x is the variable I'd like to solve and "out" and "incoming" are simply values coming from either other functions or being parameters that I can decide for myself. I

The problem for me is that Matlab can't solve the function in this shape and I have to define "out" and "incoming" with, for example
incoming = 60;
out = 5;

and put that in the function
 z = -5+ x/1000*((0.88 + 0.437*60)*(2753.9 + 1.493*60) + (0.89 + 0.132*60)*(2651.1 + 0.984*60));

which then becomes solvable. (I've been using fsolve).

But this isn't practical for me so I wonder how I should define the function so that I could use "out" and "incoming" instead of numbers, to test different scenarios?

Subject: Matlab function solving

From: Roger Stafford

Date: 20 Aug, 2013 16:07:08

Message: 2 of 3

"Mikey Evans" wrote in message <kuvtv9$gtm$1@newscl01ah.mathworks.com>...
> Hello!
>
> I'm having a bit of a problem with something that I thought would be simple:
>
> I'd like to solve a function
> z = -out + x/1000*((0.88 + 0.437*incoming)*(2753.9 + 1.493*incoming) + (0.89 + 0.132*incoming)*(2651.1 + 0.984*incoming));
>
> where x is the variable I'd like to solve and "out" and "incoming" are simply values coming from either other functions or being parameters that I can decide for myself. I
>
> The problem for me is that Matlab can't solve the function in this shape and I have to define "out" and "incoming" with, for example
> incoming = 60;
> out = 5;
>
> and put that in the function
> z = -5+ x/1000*((0.88 + 0.437*60)*(2753.9 + 1.493*60) + (0.89 + 0.132*60)*(2651.1 + 0.984*60));
>
> which then becomes solvable. (I've been using fsolve).
>
> But this isn't practical for me so I wonder how I should define the function so that I could use "out" and "incoming" instead of numbers, to test different scenarios?
- - - - - - - - - -
  For this purpose you should be using 'solve', not 'fsolve'. Your example is a simple linear case that it can easily solve. However, you should be aware that for very complicated equations, 'solve' may be unable to find a solution.

Roger Stafford

Subject: Matlab function solving

From: Steven_Lord

Date: 20 Aug, 2013 17:01:48

Message: 3 of 3



"Mikey Evans" <mik32009@live.co.uk> wrote in message
news:kuvtv9$gtm$1@newscl01ah.mathworks.com...
> Hello!
>
> I'm having a bit of a problem with something that I thought would be
> simple:
>
> I'd like to solve a function
> z = -out + x/1000*((0.88 + 0.437*incoming)*(2753.9 + 1.493*incoming) +
> (0.89 + 0.132*incoming)*(2651.1 + 0.984*incoming));
>
> where x is the variable I'd like to solve and "out" and "incoming" are
> simply values coming from either other functions or being parameters that
> I can decide for myself. I
>
> The problem for me is that Matlab can't solve the function in this shape
> and I have to define "out" and "incoming" with, for example incoming = 60;
> out = 5;
>
> and put that in the function
> z = -5+ x/1000*((0.88 + 0.437*60)*(2753.9 + 1.493*60) + (0.89 +
> 0.132*60)*(2651.1 + 0.984*60));
>
> which then becomes solvable. (I've been using fsolve).
>
> But this isn't practical for me so I wonder how I should define the
> function so that I could use "out" and "incoming" instead of numbers, to
> test different scenarios?

See the Note in the documentation for FSOLVE for how to pass additional
parameters, like out and incoming, into the function you're trying to solve.

http://www.mathworks.com/help/optim/ug/fsolve.html?searchHighlight=Extra+Parameters

But since you're solving for just one variable, you can use FZERO which
contains an example of how to do this right on its documentation page.

http://www.mathworks.com/help/matlab/ref/fzero.html?searchHighlight=Extra

I'm assuming this is just a sample problem and that your real problem is
much larger, since if this is your real problem it's simple to solve
analytically.

z = -out + x/1000*((0.88 + 0.437*incoming)*(2753.9 + 1.493*incoming) + (0.89
+ 0.132*incoming)*(2651.1 + 0.984*incoming))

Add out to both sides
z + out = x/1000*((0.88 + 0.437*incoming)*(2753.9 + 1.493*incoming) + (0.89
+ 0.132*incoming)*(2651.1 + 0.984*incoming))

Divide by the whole expression involving incoming
(z + out)/((0.88 + 0.437*incoming)*(2753.9 + 1.493*incoming) + (0.89 +
0.132*incoming)*(2651.1 + 0.984*incoming)) = x/1000

Multiply both sides by 1000
1000*(z + out)/((0.88 + 0.437*incoming)*(2753.9 + 1.493*incoming) + (0.89 +
0.132*incoming)*(2651.1 + 0.984*incoming)) = 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