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 =(

답변 (1개)

Image Analyst
Image Analyst 2022년 12월 10일

1 개 추천

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

Denis
Denis 2022년 12월 10일
편집: Denis 2022년 12월 10일
Hi! Thanks.
Sorry, now the entry is correct.
I don't know the values for the constant. Below is general task, I've alreade get the f(x) equation from initial data, but still have ploblems with the "generate surface graph"
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');
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');

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2022b

태그

질문:

2022년 12월 10일

댓글:

2022년 12월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by