How to plot the function?
3 次查看(过去 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!




