Thread Subject:
Solving simultaneous equations in matlab

Subject: Solving simultaneous equations in matlab

From: Yvonne

Date: 19 Nov, 2009 21:42:19

Message: 1 of 3

Hi,

I am trying to solve simulataneous equations to create a curve by plugging in the variables a and b into the equation Sscaled = a*Sraw + b;

HT = [32.9 32.4 34.8 35.6];
LT = [19.8 26.6 29.5 30.3];

The equations to solve a and b is
a = - (b/LT);
b= 1/((HT*(a))+b;

How can I solve the equations with two unknowns simultanously to plug into the Sscaled = a*Sraw +b;

Thank you

Subject: Solving simultaneous equations in matlab

From: Greg Heath

Date: 21 Nov, 2009 05:32:56

Message: 2 of 3

On Nov 19, 4:42 pm, "Yvonne " <h...@waikato.ac.nz> wrote:
> Hi,
>
> I am trying to solve simulataneous equations to create a curve by plugging in the variables a and b into the equation Sscaled =  a*Sraw + b;
>
> HT = [32.9 32.4 34.8 35.6];
> LT = [19.8 26.6 29.5 30.3];
>
> The equations to solve a and b is
> a = - (b/LT);
> b= 1/((HT*(a))+b;

I don't have the slightest idea of what you are trying to describe.
It would probably help if you rewrote te entire post.

Hope this helps.

Greg
> How can I solve the equations with two unknowns simultanously to plug into the Sscaled = a*Sraw +b;
>
> Thank you

Subject: Solving simultaneous equations in matlab

From: Bruce

Date: 9 Jan, 2010 07:26:05

Message: 3 of 3

"Yvonne " <hwt3@waikato.ac.nz> wrote in message <he4e3r$bol$1@fred.mathworks.com>...
> Hi,
>
> I am trying to solve simulataneous equations to create a curve by plugging in the variables a and b into the equation Sscaled = a*Sraw + b;
>
> HT = [32.9 32.4 34.8 35.6];
> LT = [19.8 26.6 29.5 30.3];
>
> The equations to solve a and b is
> a = - (b/LT);
> b= 1/((HT*(a))+b;
>
> How can I solve the equations with two unknowns simultanously to plug into the Sscaled = a*Sraw +b;
>
> Thank you

Hello Yvonne,

I have built a custom solution for you that firstly solves the simultaneous equations
you mentioned and then plots them on a graph. You had an extra left bracket in your second equation above and I was initially unsure as to whether b was in the denominator but quickly realised it must be to make sense mathematically otherwise it would equal zero once terms were collected and would only have had one unknown with no solution other than infinity. That said I rewrote the equations so they were equal to constants with all terms collected.

A chunk of my code (see below) reveals the equations in string format so they
can be used with the Symbolic Math Toolbox 'solve' command.
 %build equations
    eq1 = '((1-b^2)/b)/a = HT';
    eq2 = '-b/a = LT';
 
I used a for loop to pass all the LT and HT vector constants through the equations
and came up with a,b pair solutions. I then built graphs by plugging in the variables a and b into the equation Sscaled = a*Sraw + b with a nested for loop approach. I used a 3D matrix to hold the coordinates.

I have pasted the code below and submitted it to file exchange along with a HTML
file demonstrating it running. Note I used a script which clears memory and wipes
the command-line window prior to running. You can delete these if they are
inconvenient.

I can be emailed on my gmail email if you require further help or explanation.

Regards

Bruce R.

------------------------------------------------------------------------------------------------------

clear all; clc;

%set up row vectors
HT=[32.9 32.4 34.8 35.6];
LT=[19.8 26.6 29.5 30.3];

%iterate through the vectors
for i=1:4
    %build equations
    eq1 = '((1-b^2)/b)/a = HT';
    eq2 = '-b/a = LT';
    %substitute vector values in each algebraic equation
    eq1 = subs(eq1,'HT',HT(i));
    pretty(eq1);
    eq2 = subs(eq2,'LT',LT(i));
    pretty(eq2);
    %solve simultaneous equations for a and b
    s=solve(eq1,eq2,'a,b');
    s=[simplify(s.a) simplify(s.b)]; %solution set
    s= [eval(s(1)) eval(s(3)); eval(s(2)) eval(s(4))];
    allabs(i,1:2) = [s(1) s(3)]; %store first solution of each ab soln set.
    disp(s);
    disp(allabs);
end;

% 4 sets of x,y values for 4 graphs
for row=1:4
    %select arbitrary scale of 0 to 100
    for Sraw=0:100
        plane=row;
        %calculate the y value, Sscaled, from the x value, Sraw
        %using a 3D matrix to store everything.
        Sscaled(Sraw+1,1:2,plane) = [Sraw allabs(row,1)*Sraw + allabs(row,2)];
    end;
end;
%disp(Sscaled);
%plot the Sscaled results making 4 graphs
plot(Sscaled(:,1,1),Sscaled(:,2,1),':r.');
hold on;
plot(Sscaled(:,1,2),Sscaled(:,2,2),':g.');
plot(Sscaled(:,1,3),Sscaled(:,2,3),':b.');
plot(Sscaled(:,1,4),Sscaled(:,2,4),':y.');
xlabel('Sraw')
ylabel('Sscaled')
title('Plot for Yvonne')

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
symbolic maths too... Bruce Raine 9 Jan, 2010 02:29:12
solve Bruce Raine 9 Jan, 2010 02:29:10
rssFeed for this Thread

Contact us