How to get a graph of an equation having a sigma notation with double indices

3 views (last 30 days)
How to write a code with for loop to get a graph of the following equation?
.

Answers (1)

Amith
Amith on 21 Aug 2024
Hi Sania,
To simulate the given equation in MATLAB, you can utilize `for` loops, setting `maxIterations` to 100 to represent the limit for the infinite series. Please refer to the code below to perform the calculation:
function demomlans()
% Define the range of t values
t_values = linspace(0.1, 10, 100); % Avoid t = 0 to prevent division by zero
f_values = arrayfun(@myFunction, t_values);
% Plot the function
figure;
plot(t_values, f_values, 'LineWidth', 2);
xlabel('t');
ylabel('f(t)');
title('Plot of the function f(t)');
grid on;
end
function f = myFunction(t)
% Initialize variables
f = 0;
maxIterations = 100; % Set a limit for the infinite series
% Compute the sum
for n = 1:maxIterations %starting from 1 to avoid divide by 0 errors
for p = 1:maxIterations
term = ((-1)^n * (n/p)^p * sin(t)) / (factorial(n) * factorial(p));
f = f + term;
end
end
% Divide by t outside the sum
f = f / t;
end
The code provided above generates a graph similar to the one shown below:
Hope this helps!

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!