Thread Subject: Solving 4 equations in MAtlab

Subject: Solving 4 equations in MAtlab

From: Ashwath Sundaresan

Date: 2 Jun, 2008 01:42:02

Message: 1 of 7

Hi there

I have the following 3 equations:

y1 = a1 + (a2*t^2)/(1+ a3*t +a4*t^2)
y2 = a2*t*(2+a3*t)/(1+ a3*t +a4*t^2)^2
y3 = -2*a2*(-1+3*a4*t^2 + a3*a4*t^2)/(1+ a3*t +a4*t^2)^3

I have the following values:

y1(33) = 1.025031777
y2(33) = 0.02973
y3(33) = -0.001465
y1(1000) = 1.8

How do I solve this system in Matlab to obtain a1,a2, a3
and a4?

Cheers

Subject: Solving 4 equations in MAtlab

From: John D'Errico

Date: 2 Jun, 2008 02:06:01

Message: 2 of 7

"Ashwath Sundaresan" <asu33@student.canterbury.ac.nz> wrote in message
<g1vj5a$gco$1@fred.mathworks.com>...
> Hi there
>
> I have the following 3 equations:
>
> y1 = a1 + (a2*t^2)/(1+ a3*t +a4*t^2)
> y2 = a2*t*(2+a3*t)/(1+ a3*t +a4*t^2)^2
> y3 = -2*a2*(-1+3*a4*t^2 + a3*a4*t^2)/(1+ a3*t +a4*t^2)^3
>
> I have the following values:
>
> y1(33) = 1.025031777
> y2(33) = 0.02973
> y3(33) = -0.001465
> y1(1000) = 1.8
>
> How do I solve this system in Matlab to obtain a1,a2, a3
> and a4?

Let me guess. You have a rational quadratic
polynomial, and are given its value at both
ends of an interval, plus the derivatives of
the polynomial at one end of the interval.

Use fsolve.

John

Subject: Solving 4 equations in MAtlab

From: Ashwath Sundaresan

Date: 2 Jun, 2008 02:12:02

Message: 3 of 7

"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g1vki9$pdo$1@fred.mathworks.com>...
> "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
wrote in message
> <g1vj5a$gco$1@fred.mathworks.com>...
> > Hi there
> >
> > I have the following 3 equations:
> >
> > y1 = a1 + (a2*t^2)/(1+ a3*t +a4*t^2)
> > y2 = a2*t*(2+a3*t)/(1+ a3*t +a4*t^2)^2
> > y3 = -2*a2*(-1+3*a4*t^2 + a3*a4*t^2)/(1+ a3*t +a4*t^2)^3
> >
> > I have the following values:
> >
> > y1(33) = 1.025031777
> > y2(33) = 0.02973
> > y3(33) = -0.001465
> > y1(1000) = 1.8
> >
> > How do I solve this system in Matlab to obtain a1,a2,
a3
> > and a4?
>
> Let me guess. You have a rational quadratic
> polynomial, and are given its value at both
> ends of an interval, plus the derivatives of
> the polynomial at one end of the interval.
>
> Use fsolve.
>
> John



Yes that is correct. How do I set up my fsolve command?

Subject: Solving 4 equations in MAtlab

From: John D'Errico

Date: 2 Jun, 2008 02:36:01

Message: 4 of 7

"Ashwath Sundaresan" <asu33@student.canterbury.ac.nz> wrote in message
<g1vkti$rli$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in
> message <g1vki9$pdo$1@fred.mathworks.com>...
> > "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
> wrote in message
> > <g1vj5a$gco$1@fred.mathworks.com>...
> > > Hi there
> > >
> > > I have the following 3 equations:
> > >
> > > y1 = a1 + (a2*t^2)/(1+ a3*t +a4*t^2)
> > > y2 = a2*t*(2+a3*t)/(1+ a3*t +a4*t^2)^2
> > > y3 = -2*a2*(-1+3*a4*t^2 + a3*a4*t^2)/(1+ a3*t +a4*t^2)^3
> > >
> > > I have the following values:
> > >
> > > y1(33) = 1.025031777
> > > y2(33) = 0.02973
> > > y3(33) = -0.001465
> > > y1(1000) = 1.8
> > >
> > > How do I solve this system in Matlab to obtain a1,a2,
> a3
> > > and a4?
> >
> > Let me guess. You have a rational quadratic
> > polynomial, and are given its value at both
> > ends of an interval, plus the derivatives of
> > the polynomial at one end of the interval.
> >
> > Use fsolve.
> >
> > John
>
>
>
> Yes that is correct. How do I set up my fsolve command?

What did you try? Why not try it?

A1234 = [-2.4757 0.033492 0.027871 0.0078041]

John

Subject: Solving 4 equations in MAtlab

From: Ashwath Sundaresan

Date: 2 Jun, 2008 03:01:01

Message: 5 of 7

"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g1vmah$847$1@fred.mathworks.com>...
> "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
wrote in message
> <g1vkti$rli$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in
> > message <g1vki9$pdo$1@fred.mathworks.com>...
> > > "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
> > wrote in message
> > > <g1vj5a$gco$1@fred.mathworks.com>...
> > > > Hi there
> > > >
> > > > I have the following 3 equations:
> > > >
> > > > y1 = a1 + (a2*t^2)/(1+ a3*t +a4*t^2)
> > > > y2 = a2*t*(2+a3*t)/(1+ a3*t +a4*t^2)^2
> > > > y3 = -2*a2*(-1+3*a4*t^2 + a3*a4*t^2)/(1+ a3*t
+a4*t^2)^3
> > > >
> > > > I have the following values:
> > > >
> > > > y1(33) = 1.025031777
> > > > y2(33) = 0.02973
> > > > y3(33) = -0.001465
> > > > y1(1000) = 1.8
> > > >
> > > > How do I solve this system in Matlab to obtain
a1,a2,
> > a3
> > > > and a4?
> > >
> > > Let me guess. You have a rational quadratic
> > > polynomial, and are given its value at both
> > > ends of an interval, plus the derivatives of
> > > the polynomial at one end of the interval.
> > >
> > > Use fsolve.
> > >
> > > John
> >
> >
> >
> > Yes that is correct. How do I set up my fsolve command?
>
> What did you try? Why not try it?
>
> A1234 = [-2.4757 0.033492 0.027871 0.0078041]
>
> John

How did u get these values? my code looks like this at the
moment:


Y = [1.025031777 1.8 0.02973 -0.001465];
a = [0 0 0 0];
t = [33 1000];

a = fsolve(@(a) Equations_of_Asymptote_Fit(t,Y,a),[1 1 1
1]);


where Equations_of_Asymptote_Fit(t,Y,a) is:

function F = Equations_of_Asymptote_Fit(t,Y, a);


F = [ (a(1) + (a(2)*t(1).^2)./(1+a(3)*t(1)+a(4)*t
(1).^2)) - Y(1)
        (a(1) + (a(2)*t(2).^2)./(1+a(3)*t(2)+a(4)*t
(2).^2)) - Y(2)
        (a(2)*t(1)*(2+a(3)*t(1))./(1+a(3)*t(1)+a(4)*t(1).^2)
^2 ) - Y(3)
        (-2*a(2)*(-1+3*a(4)*t(1).^2+a(3)*t(1).^3*a(4))./(1+a
(3)*t(1)+a(4)*t(1).^2)^3 ) - Y(4)]



am not getting correct a values so unsure where to start

Cheers
Ashwath

Subject: Solving 4 equations in MAtlab

From: John D'Errico

Date: 2 Jun, 2008 03:26:01

Message: 6 of 7

"Ashwath Sundaresan" <asu33@student.canterbury.ac.nz> wrote in message
<g1vnpd$hjc$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in
> message <g1vmah$847$1@fred.mathworks.com>...
> > "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
> wrote in message
> > <g1vkti$rli$1@fred.mathworks.com>...
> > > "John D'Errico" <woodchips@rochester.rr.com> wrote in
> > > message <g1vki9$pdo$1@fred.mathworks.com>...
> > > > "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
> > > wrote in message
> > > > <g1vj5a$gco$1@fred.mathworks.com>...
> > > > > Hi there
> > > > >
> > > > > I have the following 3 equations:
> > > > >
> > > > > y1 = a1 + (a2*t^2)/(1+ a3*t +a4*t^2)
> > > > > y2 = a2*t*(2+a3*t)/(1+ a3*t +a4*t^2)^2
> > > > > y3 = -2*a2*(-1+3*a4*t^2 + a3*a4*t^2)/(1+ a3*t
> +a4*t^2)^3
> > > > >
> > > > > I have the following values:
> > > > >
> > > > > y1(33) = 1.025031777
> > > > > y2(33) = 0.02973
> > > > > y3(33) = -0.001465
> > > > > y1(1000) = 1.8
> > > > >
> > > > > How do I solve this system in Matlab to obtain
> a1,a2,
> > > a3
> > > > > and a4?
> > > >
> > > > Let me guess. You have a rational quadratic
> > > > polynomial, and are given its value at both
> > > > ends of an interval, plus the derivatives of
> > > > the polynomial at one end of the interval.
> > > >
> > > > Use fsolve.
> > > >
> > > > John
> > >
> > >
> > >
> > > Yes that is correct. How do I set up my fsolve command?
> >
> > What did you try? Why not try it?
> >
> > A1234 = [-2.4757 0.033492 0.027871 0.0078041]
> >
> > John
>
> How did u get these values? my code looks like this at the
> moment:
>
>
> Y = [1.025031777 1.8 0.02973 -0.001465];
> a = [0 0 0 0];

There is no need to predefine a.


> t = [33 1000];
>
> a = fsolve(@(a) Equations_of_Asymptote_Fit(t,Y,a),[1 1 1
> 1]);
>
>
> where Equations_of_Asymptote_Fit(t,Y,a) is:
>
> function F = Equations_of_Asymptote_Fit(t,Y, a);
>
>
> F = [ (a(1) + (a(2)*t(1).^2)./(1+a(3)*t(1)+a(4)*t
> (1).^2)) - Y(1)
> (a(1) + (a(2)*t(2).^2)./(1+a(3)*t(2)+a(4)*t
> (2).^2)) - Y(2)
> (a(2)*t(1)*(2+a(3)*t(1))./(1+a(3)*t(1)+a(4)*t(1).^2)
> ^2 ) - Y(3)
> (-2*a(2)*(-1+3*a(4)*t(1).^2+a(3)*t(1).^3*a(4))./(1+a
> (3)*t(1)+a(4)*t(1).^2)^3 ) - Y(4)]
>
>
>
> am not getting correct a values so unsure where to start
>
> Cheers
> Ashwath

Y1 = @(A,t) A(1) + (A(2)*t^2)/(1+ A(3)*t +A(4)*t^2);
Y2 = @(A,t) A(2)*t*(2+A(3)*t)/(1+ A(3)*t +A(4)*t^2)^2;
Y3 = @(A,t) -2*A(2)*(-1+3*A(4)*t^2 + A(3)*A(4)*t^2)/(1+ A(3)*t
+A(4)*t^2)^3;

fun = @(A) [Y1(A,33),Y2(A,33),Y3(A,33),Y1(A,1000)]-Yaim;
Yaim = [1.025031777, 0.02973, -0.001465 ,1.8];

A1234 = fsolve(fun,[1 2 3 4])
Optimization terminated: first-order optimality is less than options.TolFun.
A1234 =
      -2.4757 0.033492 0.027871 0.0078041

fun(A1234) % test the result
ans =
   7.8512e-11 -6.917e-14 -1.2392e-13 4.2637e-11


Unfortunately, other starting points generate other
solutions.


Afinal2 = fsolve(fun,[1 1 1 1])
Optimization terminated: first-order optimality is less than options.TolFun.
Afinal2 =
     -0.64519 0.005712 0.0056858 0.0023293
fun(Afinal2)
ans =
   3.4817e-13 1.835e-14 -3.0835e-16 1.0774e-12


This suggests that your problem may not
be well posed, in that there is no unique
solution. It may be numerical issues too,
since you have large numbers in t. So plot
the results.

Y1vect = @(A,t) A(1) + (A(2)*t.^2)./(1+ A(3)*t +A(4)*t.^2);

ezplot(@(t) Y1vect(Afinal,t),[33,300])
hold on
ezplot(@(t) Y1vect(Afinal2,t),[33,300])

See that both sets of numbers solve your
aims, yet they have slightly different shapes.

John

Subject: Solving 4 equations in MAtlab

From: Ashwath Sundaresan

Date: 2 Jun, 2008 07:11:01

Message: 7 of 7

"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g1vp89$qjv$1@fred.mathworks.com>...
> "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
wrote in message
> <g1vnpd$hjc$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in
> > message <g1vmah$847$1@fred.mathworks.com>...
> > > "Ashwath Sundaresan" <asu33@student.canterbury.ac.nz>
> > wrote in message
> > > <g1vkti$rli$1@fred.mathworks.com>...
> > > > "John D'Errico" <woodchips@rochester.rr.com> wrote
in
> > > > message <g1vki9$pdo$1@fred.mathworks.com>...
> > > > > "Ashwath Sundaresan"
<asu33@student.canterbury.ac.nz>
> > > > wrote in message
> > > > > <g1vj5a$gco$1@fred.mathworks.com>...
> > > > > > Hi there
> > > > > >
> > > > > > I have the following 3 equations:
> > > > > >
> > > > > > y1 = a1 + (a2*t^2)/(1+ a3*t +a4*t^2)
> > > > > > y2 = a2*t*(2+a3*t)/(1+ a3*t +a4*t^2)^2
> > > > > > y3 = -2*a2*(-1+3*a4*t^2 + a3*a4*t^2)/(1+ a3*t
> > +a4*t^2)^3
> > > > > >
> > > > > > I have the following values:
> > > > > >
> > > > > > y1(33) = 1.025031777
> > > > > > y2(33) = 0.02973
> > > > > > y3(33) = -0.001465
> > > > > > y1(1000) = 1.8
> > > > > >
> > > > > > How do I solve this system in Matlab to obtain
> > a1,a2,
> > > > a3
> > > > > > and a4?
> > > > >
> > > > > Let me guess. You have a rational quadratic
> > > > > polynomial, and are given its value at both
> > > > > ends of an interval, plus the derivatives of
> > > > > the polynomial at one end of the interval.
> > > > >
> > > > > Use fsolve.
> > > > >
> > > > > John
> > > >
> > > >
> > > >
> > > > Yes that is correct. How do I set up my fsolve
command?
> > >
> > > What did you try? Why not try it?
> > >
> > > A1234 = [-2.4757 0.033492 0.027871
0.0078041]
> > >
> > > John
> >
> > How did u get these values? my code looks like this at
the
> > moment:
> >
> >
> > Y = [1.025031777 1.8 0.02973 -0.001465];
> > a = [0 0 0 0];
>
> There is no need to predefine a.
>
>
> > t = [33 1000];
> >
> > a = fsolve(@(a) Equations_of_Asymptote_Fit(t,Y,a),[1 1
1
> > 1]);
> >
> >
> > where Equations_of_Asymptote_Fit(t,Y,a) is:
> >
> > function F = Equations_of_Asymptote_Fit(t,Y, a);
> >
> >
> > F = [ (a(1) + (a(2)*t(1).^2)./(1+a(3)*t(1)+a(4)*t
> > (1).^2)) - Y(1)
> > (a(1) + (a(2)*t(2).^2)./(1+a(3)*t(2)+a(4)*t
> > (2).^2)) - Y(2)
> > (a(2)*t(1)*(2+a(3)*t(1))./(1+a(3)*t(1)+a(4)*t
(1).^2)
> > ^2 ) - Y(3)
> > (-2*a(2)*(-1+3*a(4)*t(1).^2+a(3)*t(1).^3*a(4))./
(1+a
> > (3)*t(1)+a(4)*t(1).^2)^3 ) - Y(4)]
> >
> >
> >
> > am not getting correct a values so unsure where to start
> >
> > Cheers
> > Ashwath
>
> Y1 = @(A,t) A(1) + (A(2)*t^2)/(1+ A(3)*t +A(4)*t^2);
> Y2 = @(A,t) A(2)*t*(2+A(3)*t)/(1+ A(3)*t +A(4)*t^2)^2;
> Y3 = @(A,t) -2*A(2)*(-1+3*A(4)*t^2 + A(3)*A(4)*t^2)/(1+ A
(3)*t
> +A(4)*t^2)^3;
>
> fun = @(A) [Y1(A,33),Y2(A,33),Y3(A,33),Y1(A,1000)]-Yaim;
> Yaim = [1.025031777, 0.02973, -0.001465 ,1.8];
>
> A1234 = fsolve(fun,[1 2 3 4])
> Optimization terminated: first-order optimality is less
than options.TolFun.
> A1234 =
> -2.4757 0.033492 0.027871 0.0078041
>
> fun(A1234) % test the result
> ans =
> 7.8512e-11 -6.917e-14 -1.2392e-13 4.2637e-11
>
>
> Unfortunately, other starting points generate other
> solutions.
>
>
> Afinal2 = fsolve(fun,[1 1 1 1])
> Optimization terminated: first-order optimality is less
than options.TolFun.
> Afinal2 =
> -0.64519 0.005712 0.0056858 0.0023293
> fun(Afinal2)
> ans =
> 3.4817e-13 1.835e-14 -3.0835e-16 1.0774e-12
>
>
> This suggests that your problem may not
> be well posed, in that there is no unique
> solution. It may be numerical issues too,
> since you have large numbers in t. So plot
> the results.
>
> Y1vect = @(A,t) A(1) + (A(2)*t.^2)./(1+ A(3)*t +A(4)
*t.^2);
>
> ezplot(@(t) Y1vect(Afinal,t),[33,300])
> hold on
> ezplot(@(t) Y1vect(Afinal2,t),[33,300])
>
> See that both sets of numbers solve your
> aims, yet they have slightly different shapes.
>
> John


Thanks for that

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
homework John D'Errico 1 Jun, 2008 22:40:06
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com