Please help with looping
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Azzi Abdelmalek
on 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)
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!