How can I code a two variable function?

10 vues (au cours des 30 derniers jours)
Eduardo Fornazieri
Eduardo Fornazieri le 10 Juil 2021
Modifié(e) : ANKUR KUMAR le 11 Juil 2021
Hi, could you code this function from ?
I know I can't do it to infinity, so I choose the sum from 0 to 100. Please, help.
.

Réponse acceptée

ANKUR KUMAR
ANKUR KUMAR le 11 Juil 2021
Modifié(e) : ANKUR KUMAR le 11 Juil 2021
You can simply use for loop to iterate x and y. Refer to the below code just for your reference. You might need to make modification as per your need.
This might be the good starting point for you to write code independently.
Anyway, I am getting some of the NaN values.
func = @(n,x,y) (((-1)^n)/((2*n + 1)^3))* sech(((2*n + 1)*pi)/2)*cosh(((2*n + 1)*pi*x)/2)*cos(((2*n + 1)*pi*y)/2);
n_upper_limit=100;
for x=1:5
for y=1:5
u(x,y) = 1- y^2 - ((32)/(pi^3))*(sum(arrayfun(@(n) func(n,x,y), 1:n_upper_limit),'omitnan'));
end
end
disp(u)
1.0e+130 * -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 1.6033 0.0000 -1.6033 -0.0000 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
% For plotting u
imagesc(u)
title('Values of u')
xlabel('x values')
ylabel('y values')
xticks([1:5])
yticks([1:5])
colorbar
set(gca,'Ydir','normal')

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by