Please help with looping

1 次查看(过去 30 天)
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.

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2012-10-8
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by