|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jpo84r$8ao$1@newscl01ah.mathworks.com>...
> "Marc " <job21marc@hotmail.com> wrote in message <jpngc1$r4c$1@newscl01ah.mathworks.com>...
>
> >
> > wow, thank you Bruno but I don't see how to make it. my code is simple,
> > for example, how can you calculated min and max from that:
> > >> x=1:10;
> > >> x=0:10;
> > >> y=[3 4 8 9 5 7 2 9 4 6 1];
> > >> cs=spline(x,y);
> >
>
> x=0:10;
> y=[3 4 8 9 5 7 2 9 4 6 1];
> cs=spline(x,y);
>
> coefs = cs.coefs;
> a = 3*coefs(:,1);
> b = 2*coefs(:,2);
> c = 1*coefs(:,3);
> delta = b.^2 - 4*a.*c;
> x1 = (-b - sqrt(delta)) ./ (2*a);
> x2 = (-b + sqrt(delta)) ./ (2*a);
> left = cs.breaks';
> h = diff(left);
> b1 = delta >= 0 & x1 >= 0 & x1 <= h;
> b2 = delta >= 0 & x2 >= 0 & x2 <= h;
> x = [left(1);
> left(b1) + x1(b1); ...
> left(b2) + x2(b2);
> left(end)];
>
> [ymax imax] = max(ppval(cs,x));
> xmax = x(imax);
>
> fprintf('ymax = %g\n', ymax);
> xi = linspace(0,10);
> figure;
> plot(xi, ppval(cs, xi), 'b', xmax, ymax, 'or')
>
> % Bruno
Thanks so much Bruno, now i stil have a problem that i don't know how to solve....
I'm doing two interpolation, this code works perfect with one but with the other is more complicated to implement i think.
The point is that I interpolate a spline([157x1],[168x157]) and the result is:
form: 'pp'
breaks: [1x157 double]
coefs: [26208x4 double]
pieces: 156
order: 4
dim: 168
I saw that they put all the coefs together but this is not the problem because I can do it with a for and step-by-step. The problem is that now x1 and x2 are 168x1 and h is 156X1 and I have a problem in:
b1 = delta >= 0 & x1 >= 0 & x1 <= h;
b2 = delta >= 0 & x2 >= 0 & x2 <= h;
because they are not of the same size....
the 168X157 is a diagonal matrix of 1 in the diagonal and 0 rest and the 157x1 is a 0:0.02:3 and adding all the 0.25-0.75-1.25-1.75-2.25-2.75.
thanks for everything again, you're helping me so much.
|