[Scilab-users] {EXT} Using lsqrsolve with a certain kind of function

Viktor Goryainov al_exquemelin at yahoo.com
Fri Dec 23 22:51:11 CET 2016


Thank you for the reply, but that's not exactly what I needed. Perhaps I 
didn't make myself clear. My vr3() function already does return a 15x1 
vector (or maybe, I should call it a column), because a_w15 (b_w15 and 
so on) are all 15x1 matrices.

Suppose for clarity I make mu and everything else global, and leave 
vr3(C) with the same lines inside that I wrote earlier. I can use it on 
some C_inh, like this for example:

C_inh = [0.5 0.5 0.8];
s = vr3(C_inh);

Then, I take some other values as an initial guess, say C_init = [1 1 
1], and try to restore C_inh using lsqrsolve(). As far as I can see from 
its help page, I need a function of the following kind:

function e = err(C2)
  e = s - vr3(C2);
endfunction

But it wouldn't work: [C, v] = lsqrsolve(C_init, err, 15) gives me error 
58: Function has no input argument. Seems either vr3() must be modified 
to work with individual values, or I'm doing something wrong.

Best regards,
Viktor

22.12.2016 11:33, Dang Ngoc Chan, Christophe пишет:
> Hello,
>
>> De : Viktor Goryainov
>> Envoyé : mercredi 21 décembre 2016 16:43
>>
>> I have a function that takes tabulated values from several arrays (a_w15, b_w15, etc.) and thus returns a vector:
>> [...]
>> Now I need to [...] generate a vector
>
> I'm not sure I understand well your problem with lsqrsolve(),
> but if you want to generate a vector,
> you should replace the if test by something like
>
> ----------
> r = zeroes (dd); // initialization, not necessary but imho good practice
> ddboolean = (dd<0.25);
> r(ddboolean) = 0.319 * dd(ddboolean) / mu;
> r(~ddboolean) = (0.267 * dd(~ddboolean)  + 0.013) / mu;
> ----------
>
> So the whole function may look like:
>
> ----------
> function r = vr3(C, mu)
>   a = a_w15 + a_chl15 * C(1) + a_sm15 * C(2) + a_doc15 * C(3);
>   bb = b_w15 + b_chl15 * C(1) + b_sm15 * C(2);
>   dd = bb ./ a;
>
> r = zeroes (dd);
> ddboolean = (dd<0.25);
> r(ddboolean) = 0.319 * dd(ddboolean) / mu;
> r(~ddboolean) = (0.267 * dd(~ddboolean)  + 0.013) / mu;
> endfunction
> ----------
>
> Hope this helps
>
> --
> Christophe Dang Ngoc Chan
> Mechanical calculation engineer
> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>



More information about the users mailing list