how to define a function handle if i need to define a function from R^n to R?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello! I'm sorry for my dumb question but i need to define a function f(x) from R^n to R where n is very large (say n=1000) but if I use the command f = @(x) = sum(1/2*x(i,:)^2+x(i,:)) it gives me error if I try to insert a x wich belongs to R^n and it only works if I put a scalar value. What's the correct sintex? How do I define this function?
1 comentario
James Tursa
el 16 de Dic. de 2020
I am confused about what you want. Can you provide a short example of input and desires output? E.g., what would be the desired output for the following inputs:
x = reshape(1:24,2,3,4);
x = reshape(1:120,2,3,4,5);
Respuestas (1)
Star Strider
el 16 de Dic. de 2020
I am not certain what you are doing or what result you want.
Try these to see which one gives you what you want:
fr = @(x) sum(1/2*x(:).^2+x(:),2); % Use Element-Wise exponentiation (.^) & Force Column Vectors To Sum Across Columns
fc = @(x) sum(1/2*x(:).^2+x(:)); % Use Element-Wise exponentiation (.^) & Force Column Vectors To Sum Down Columns
x = rand(5,1);
yr = fr(rx);
yc = fc(x);
.
0 comentarios
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!