MATLAB Answers

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.

3 views (last 30 days)
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

Accepted Answer

Antonio Aguirre
Antonio Aguirre on 13 Aug 2020
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' )

More Answers (1)

Sudheer Bhimireddy
Sudheer Bhimireddy on 10 Aug 2020
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.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by