How to plot the function?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello. Could you please help me? I am not sure how to plot this function using Matlab. I am new to Matlab, so just trying =(

댓글 수: 0
답변 (1개)
Image Analyst
2022년 12월 10일
Can you tell us what the values of a, b, k, t, and epsilon are? Then just take it one term at a time. And there is an ambiguity around x because of missing parentheses. Can you tell us if x is inside the sine argument, or between the sin and cos terms?
a = 2;
b = 1;
c = 1;
k = 1;
t = 1;
epsilon = 1;
x = linspace(0, 5*pi, 1000);
for index = 1 : numel(x)
thisx = x(index);
term1 = (2 * epsilon * a^2) / (pi^2 * b * (a - b));
term2 = sin(pi * k * b / a) / k^2;
term3 = sin(pi * k * thisx / a); % Does x really go here like this???
term4 = cos(pi * k * c * t / a);
f(index) = term1 * sum(term1 .* term2 .* term3);
end
plot(x, f, 'b-', 'LineWidth', 2)
grid on
xlabel('x');
ylabel('f');
댓글 수: 3
Image Analyst
2022년 12월 10일
OK that's the formula I put in. If you don't know the values of the constant parameters, then you cannot plot it.
I have no idea about "generate surface graph". Where did you get that from? Is this a homework? If so, read this link: How do I get help on homework questions on MATLAB Answers? - MATLAB Answers - MATLAB Central
You can't really get a surface unless you have another axis. f(x) is a one dimensional signal. Does any of the other parameters vary? Like k or t maybe? If so you could use surf to plot f(x, k) or f(x, t).
a = 2;
b = 1;
c = 1;
k = 1;
t = 1;
epsilon = 1;
x = linspace(0, 5*pi, 1000);
for index = 1 : numel(x)
thisx = x(index);
term1 = (2 * epsilon * a^2) / (pi^2 * b * (a - b));
% Sum over k
for k = 1 : 1000
term2 = sin(pi * k * b / a) / k^2;
term3 = sin(pi * k * thisx / a); % Does x really go here like this???
term4 = cos(pi * k * c * t / a);
f(index, k) = term1 * sum(term1 .* term2 .* term3);
end
end
k = 1 : 1000;
surf(x, k, f, 'EdgeColor','none')
grid on
xlabel('x');
ylabel('f');
Torsten
2022년 12월 10일
Here is the code for one value of t.
Add a second loop over t-values to produce a surface plot.
a = 2;
b = 1;
c = 10;
k = 1;
t = 1;
epsilon = 1;
term1 = (2 * epsilon * a^2) / (pi^2 * b * (a - b));
x = linspace(0, a, 1000);
f = zeros(size(x));
for index = 1 : numel(x)
thisx = x(index);
% Sum over k
for k = 1 : 1000
term2 = sin(pi * k * b / a) / k^2;
term3 = sin(pi * k * thisx / a); % Does x really go here like this???
term4 = cos(pi * k * c * t / a);
f(index) = f(index) + term2 * term3 * term4;
end
end
f = f * term1;
plot(x, f)
grid on
xlabel('x');
ylabel('f');
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




