Please help with looping

1 visualización (últimos 30 días)
Enfa White
Enfa White el 8 de Oct. de 2012
Sorry, correction for input value, a(2)
I created a function as follows and have 2 input values labelled as a(1) and a(2)
function my_function = func_two(a)
x = (1+sin(5*a(1))-(1/sqrt(8*(sin(a(1))))))
y = (1+sin(5*a(2))+(1/sqrt(8*(sin(a(2))))))
func_two = x + y
func_three = x + y + x
func_four = x + y + x + y
and so on. E.g For func_four, I tried with x + y + x + y, but it didn't work, so I put the full equation:
e.g func_four = (1+sin(5*a(1))-(1/sqrt(8*(sin(a(1))))))...
+(1+sin(5*a(2))+(1/sqrt(8*(sin(a(2))))))...
+(1+sin(5*a(1))-(1/sqrt(8*(sin(a(1))))))...
+(1+sin(5*a(2))+(1/sqrt(8*(sin(a(2))))));
How to create a loop to simplify this function, if I want to have func_ten or func_twenty? TQ.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 8 de Oct. de 2012
function out=nth(x,y,n)
if fix(n/2)==n/2
out=n*(x+y)
else
out=(n-1)*(x+y)+x
end
then
out=nth(12,14,5)

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by