Effacer les filtres
Effacer les filtres

Please help with looping

1 vue (au cours des 30 derniers jours)
Enfa White
Enfa White le 8 Oct 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.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 8 Oct 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)

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by