I have to solve the equation for 'a'.
Now x are the elements in the following array:
x=[0.56746089 0.60481729 0.622521 0.53714241 0.60310756 1.07806689 1.19968209 1.05637284 1.14618436 0.94031809];
My problem is that I do not know how to call the elements in the array in a function.

 Respuesta aceptada

Brian Voke
Brian Voke el 10 de Mayo de 2021

0 votos

To call a specific element from an array or matrix you can use this notation: for matrix x the first element would be x(1), the second element would be x(2) and so on. If you're just trying to find the solution to that equation where each element in a corresponds to a solution with a single element in x then you can write the equation using element wise operators to multiply matrices element wise the operator is preceded with period. (So a times x would be written as a .*x). Then you could solve the equation using the solve function.

6 comentarios

J.Cam
J.Cam el 10 de Mayo de 2021
Thanks for the reply, I tried this but I kept having an error.
x=[0.7569
0.69956496
0.60109009
0.67519089
0.14676561
0.72607441
0.65302561
0.40106889
0.71284249
0.69022864];
syms a
m=((x(i,1)).*cos(a.*(x(i,1)))./(sin(a.*((x(i,1))))));
ftn = 10/a + symsum(m,1,10)
value=vpasolve(ftn==0,a)
Brian Voke
Brian Voke el 10 de Mayo de 2021
I'm not sure exactly how you'd format this to work, but I believe your current error is that your trying to use symsum to sum the variable i, but you do not have i as a symbolic variable. Including i as a symbolic variable is a step in the right direction, but I think you may have to look more into the inputs and setup for symsum before you'll get this working right.
J.Cam
J.Cam el 10 de Mayo de 2021
What's the best way to go about it? Is there an easier way?
Brian Voke
Brian Voke el 10 de Mayo de 2021
I would double check to make sure I didn't mess up any parantheses but I think this is a solution. This works because there's only 10 elements in the x matrix so it's not like you need to specify which elements you want to run then sum. The elementwise multiplication makes it so that the resulting m matrix has 10 elements each corresponding to an element in x. So the normal sum function should work.
x=[0.7569
0.69956496
0.60109009
0.67519089
0.14676561
0.72607441
0.65302561
0.40106889
0.71284249
0.69022864];
syms a
m=(x.*cos(a.*(x))./(sin(a.*x)));
ms=sum(m);
ftn = 10/a + ms;
value=vpasolve(ftn==0,a)
J.Cam
J.Cam el 10 de Mayo de 2021
This worked! Thank you!
Brian Voke
Brian Voke el 10 de Mayo de 2021
No problemo

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Mayo de 2021

Comentada:

el 10 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by