With what code can I make Matlab do this operation automatically

Good morning.
I hope you can help me.
How can I enter the elements of a vectror automatically in the formula, to obtain the value of E and then introduce the elements of the next vector. Everything automatically.
____________________________
clc; clear; close all
x1=[1 2 3 4 5 6 7 8 9 10]
x2=[2 4 6 8 1 3 5 2 3 1]
x3=[2 1 4 2 6 4 8 3 8 3]
E=exp(x1(1))+exp(x1(2))+exp(x1(3))+exp(x1(4))+exp(x1(5))+exp(x1(6))+exp(x1(7))+exp(x1(8))+exp(x1(9))+exp(x1(10))
__________________________________________________________________________________________________
Regards

3 comentarios

abuzer
abuzer el 23 de En. de 2018
Editada: abuzer el 23 de En. de 2018
clc; clear; close all
x1=[1 2 3 4 5 6 7 8 9 10];
x2=[2 4 6 8 1 3 5 2 3 1];
x3=[2 1 4 2 6 4 8 3 8 3];
% your function
E=exp(x1(1))+exp(x1(2))+exp(x1(3))+exp(x1(4))+...
exp(x1(5))+exp(x1(6))+exp(x1(7))+exp(x1(8))+exp(x1(9))+exp(x1(10))
eks = @(x) sum(exp(x));
E1 = eks(x1)
First thanks for answering. I have E1 is evaluated with the vector A0, now it is necessary to evaluate with the vector A1 and A2. Evaluate A0, A1 and A2 automatically. Thanks and regards
Excellent!!! You are a genius. Thank you

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 23 de En. de 2018
Editada: Star Strider el 23 de En. de 2018
Try this:
E = sum(exp(x1))
E =
34.8438
You can also create an anonymous function to do this:
Efcn = @(x) sum(exp(x));
E = Efcn(x1)
and use it as you would any other function.
EDIT (23 Jan 2018 21:38 UCT)
To do all of them at once:
x1=[1 2 3 4 5 6 7 8 9 10];
x2=[2 4 6 8 1 3 5 2 3 1];
x3=[2 1 4 2 6 4 8 3 8 3];
E = sum(arrayfun(@exp, [x1; x2; x3]), 2)
E =
34.8438
3.6478
6.5322

2 comentarios

Excellent!!! You are a genius. Thank you
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 23 de En. de 2018

Comentada:

el 24 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by