Filter löschen
Filter löschen

Please help with looping

1 Ansicht (letzte 30 Tage)
Enfa White
Enfa White am 8 Okt. 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.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 8 Okt. 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)

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by