help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: leasqr problem


From: Jaroslav Hajek
Subject: Re: leasqr problem
Date: Mon, 26 Jan 2009 11:21:49 +0100

On Sat, Jan 24, 2009 at 1:12 PM, Jose Rodriguez
<address@hidden> wrote:
> Hello
>
> I'm trying to solve a problem with leasqr, where the observed
> value, instead of being a set of points y=f(x), is the result of a
> definite integral. I found that I can use leasqr if I adjust the
> dimensions of the function to fit and its expected values to the
> dimension of the x range:
>
> x=(0:0.1:pi);
>
> P=@(x)  1/2 * ( 3*cos(x).^2-1 );
>
> F=inline( " ones ( size(x,1), 1 ) * trapz( x, P(x).*
> exp(-a*P(x)).*sin(x) ) ", "x", "a" );
>
> y=0.5 * ones ( size(x,1), 1 );
> pin=1;
>
> [f,p,kvg,iter,corp,covp,covr,stdresid,Z,r2]=leasqr(x, y, pin, F);
>
>
> If I run this I obtain the value 'a' for which the integral:
>
> trapz( x, P(x) .* exp(-a*P(x)) .* sin(x) )
>
> is 0.5.
>
> My problem is that I also want to include a normalisation
> condition, like:
>
> 1 = trapz( x, exp(-a*P(x)).*sin(x) )
>
> And I thought that I could build F in two columns, the first of
> them identical to what I've written above and the second with the
> normalisation condition, adjusting again the number of rows to the
> x dimension:
>
> F=inline( " [ ones ( size(x,1), 1 ) * trapz( x, P(x).*
> ( a(1)*exp(-a(2)*P(x)).*sin(x) )   ones ( size(x,1), 1 ) *
> trapz( x,  a(1)*exp(-a(2)*P(x)) .*sin(x) ) ] ", "x", "a" );
>
> y=[0.5*ones(size(x,1),1)  ones(size(x,1),1)];
> pin=[1 1]';
>
> But this triggers an error from leasqr.m:
>
> "input(x)/output(y) data must have same number of
> rows"
> error: evaluating if command near line 162, column 1
>
> because the script converts all the vectors to columns and thus
> size(y(:)) is the double of size(x,1).
>
> Could somebody give me some pointers as to how to proceed? Or am I
> completely out of track?
>

I'm not sure I understand what you're trying to do.
The condition 1 == trapz( x, exp(-a*P(x)).*sin(x) ) is generally
enough to determine a,
because you have a single equation with a single variable.
So is the other equation,
trapz( x, P(x) .* exp(-a*P(x)) .* sin(x) ) == 0.5, but generally, you
can't satisfy a system of two equations
simultaneously if you only have one variable. Such a system may be
solved in a least-squares sense, but
is that what you need?




-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]