I want to plot a graph like this in Matlab. It would be a great help if someone can help me with the same by providing the code.

1 次查看(过去 30 天)
The function is
y(x,t) = ((c1*x )+ (c2*x^2)) * (0.08*x) * (sin((10.2*x)+(2*pi*i/8))) * (sin((10.2*x)-(2*pi*i/8)))
c1 = 0.08
c2 = 0
i = 1 to 7

采纳的回答

Antonio Aguirre
Antonio Aguirre 2020-8-13
Hi,
So I tried the following below. Minus the LaTeX formatting, I think it's exactly what you need. Also, the function that you gave does not produce the necessary values to produce the example plot that you showed in your post. Any way, check out what I've done and maybe I've got a typo in the function. Don't forget to give me a "Thumbs Up" vote if this was helpful, thanks!
%% Start clean and clear
clc,clear,close all
%% Define constants
c1 = 0.08;
c2 = 0;
c3 = 10.2;
%% Define the function to plot, anonymous function
fcn = @(i,x,c1,c2,c3) ( (c1.*x) + (c2.*x.^2) ) .* ( c1.*x ) .* ( sin( (c3.*x) + (2*pi*i/8) ) ) .* ( sin( (c3.*x) - (2*pi*i/8) ) );
%% Define the domain of the function
x = 0:0.001:0.6;
%% Initialize the figure space
figure
hold on
%% Iterate to plot the function
for i = 1:7
% Return the function response
y = fcn( i, x, c1, c2, c3 );
% Plot the function response
plot( x, y, 'b' )
% Add a data label to the line
text( x(end)+0.005, y(end), sprintf('i = %d', i) )
end
%% Configure the plot aesthetics
grid on
xlim( [0,0.7] )
xlabel( 'x (m)' )
ylabel( 'y (m)' )
title( 'c1 = 0.08 c2 = 0' )

更多回答(1 个)

Sudheer Bhimireddy
Sudheer Bhimireddy 2020-8-10
Neglecting i=0, you will have 7 lines governed by that equation.
Have you tried it by using a simple loop for i = 1:7 ?
x = 0:0.01:1;
for i = 1:7
y(:,i) = %Your equation
end
Show us what you have tried and where you are facing a problem.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by