Question: I ' m plotting a fourier series graph. Below are my matlab codings. But they seem so stupid ( hoewever I still achive the things
Im plotting a fourier series graph. Below are my matlab codings. But they seem so stupid hoewever I still achive the things I want, Just the code is so stupid that it takes for loop and if how can i modify it so that it only take loop and if to make it more efficient, while producing the same result my graph
BEJ Preproject Task
T;
tau ;
t ::;
figure;
Define the function for coefficient xn
Use @n because later I can sub n with something using xnn
Coefficientofindividualterm @ntau T sincn tau T;
If don't understand, gemini answer me better than the matlab documentation
Method directly open a new matlab to test to see what I get,
then I would understand
Finalxt zerossizet;
n
for n :; Later ask, how to implement using for, and if
because this loop would sub in n
this would cause incorrectness!
i want it to skip when n
So only if when the n is not execute the following!
if absn
Individualtermofxt tau T sincn tau T expj pi n t T;
Finalxt Finalxt Individualtermofxt;
The plot function, put inside this if or it would show nothing
subplot put first, before the plot function, or it would bug! Found
by trial and error, and deduction, just now the title won't show,
observation!
subplot
plott realFinalxt;
titlext for n to ;
xlabelTime s;
ylabelAmplitude;
grid on;
end end the if statement
end end the for loop
n
Reset again the xt put here, or the following one, would produce
incorrect result, because the Finalxt would have value already
Finalxt zerossizet;
for n :;
if absnIf don't want calculate n then put if n~
Individualtermofxt tau T sincn tau T expj pi n t T;
Finalxt Finalxt Individualtermofxt;
subplot
plott realFinalxt;
titlext for n to ;
xlabelTime s;
ylabelAmplitude;
grid on;
end
end
n
Finalxt zerossizet;
for n :;
if absn
Individualtermofxt Coefficientofindividualtermn expj pi n t T;
Finalxt Finalxt Individualtermofxt;
subplot
plott realFinalxt;
titlext for n to ;
xlabelTime s;
ylabelAmplitude;
grid on;
end
end
How to plot the coefficients xn on the fourth row?
subplot;
How to declare n Use mass declaration, mass declaration, of n values,
and very fast declaration, from n to this would become an array
nvalues :;
Apply the function, Coefficientofindividualterm, on every elements of the nvalues, which is a array
Or in other words, sub in all the nvalues : into the function of Coefficientofindividualterm
It's mass substitution of element array into the function so use arrayfun, instead of sub
But why? And the outcome is what? although this is intermediate, still need the outcome!
xnvalues arrayfunCoefficientofindividualterm, nvalues;
How to do discrete plotting? Use stemplot, only got bubble,
stemnvalues, absxnvalues; Do they need all to be absolute value according to theory?
titleMagnitude of Coefficients Xn;
xlabeln;
ylabelXn;
grid on;
Actually below don't need!
Apply ifelse for conditional coefficient plotting
for idx :lengthnvalues
n nvaluesidx;
if absn
Only plot coefficients for n within range
coeffvalue absCoefficientofindividualtermn;
else
coeffvalue ; Default or outofrange handling
end
end
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
