Array indices must be positive integers or logical values.

More Answers (1)

2 Comments

now I change f in 1X9 but I have again the same problem
  • you are constructing F and Fy to be functions that require three input variables (x, y, f) but you are only passing two inputs to them
  • The equations you posted strongly suggest that P(x) is intended to mean that P is a function of x that should return a result that is the same length as x. P is a function, not an array.
  • No comments are present as to what size F(x,y) needs to return, such as if x and y are different sizes.
  • I would suggest to you that the f you use in F needs to be the same size as y, not a fixed size. Not unless you are willing to fix the size of y -- and in that case you should probably be passing in n or creating n... which would reflect into the size you create for P .
  • You never vary x once you initialize it. Perhaps your P should be a function that ignores its input and returns a vector of length n-1 .
  • Don't use inline().
%replace the *body* of esempio* with the following
Pdata = [-20,-10,0,10,20,10,0,-10,-20];
fdata = [2,3,4,5,6,5,4,3,2] .';
P = @P9;
F = @F9;
Fy = @Fy9;
a = 0;
b = 1;
alfa = 1;
beta = 1;
function Px = P9(x) %vector result, orientation not important
assert(numel(x) == numel(Pdata), 'x wrong size for P');
Px = reshape(Pdata, size(x));
end
function Fxy = F9(x, y) %column vector result!
assert(numel(y) == numel(fdata), 'y wrong size for F');
Fxy = fdata .* 2.* y(:);
end
function Fyxy = Fy9(x, y) %column vector result!
assert(numel(y) == numel(fdata), 'y wrong size for Fy');
Fyxy = fdata .* 2;
end
end %this END is important!
It is important that P9, F9, Fy9 are nested functions within the esempio* function, not independent functions. They must be nested, in order to access the Pdata and fdata arrays.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!