Wrong answer to straightforward problem:
Mostra commenti meno recenti
* Write a function called triangle_wave that computes the sum

for each of 1001 values of t uniformly spaced from 0 to 4π inclusive. The input argument is a scalar non-negative integer n, and the output argument is a row vector of 1001 such sums—one sum for each value of t. You can test your function by calling it with n == 20 or greater and plotting the result and you will see why the function is called “triangle_wave”.
My code is:
function [ out ] = triangle_wave( n )
%TRIANGLE_WAVE Summary of this function goes here
% Detailed explanation goes here
t = 4*pi/1000;
tvector = 0:t:4*pi;
length(tvector)
out = 0;
for count = 1:n+1
A= -1^(count-1);
B = sin((2*(count-1)+1)*tvector);
C = (2*(count-1)+1)^2;
triangle = A*B/C;
out = out + triangle;
end
end
This seems like it should be fairly straightforward.
Risposta accettata
Più risposte (1)
DJ V
il 6 Dic 2016
0 voti
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!