Evaluating a function with respect to 2 variables

1 visualización (últimos 30 días)
Larry McNamara
Larry McNamara el 16 de Oct. de 2017
Respondida: BhaTTa el 25 de Oct. de 2024
I've haven't used matlab in 10 years and I'm struggling to evaluate a function for "N" odd iterations from 1-5 and 1-100 with respect to 'x'. I'm required to use 100 values for 'x'. My code thus far is below.
% Constants
D = 2; %cm
SigmaA = .1; %cm^-1
SigmaF = .12; %cm^-1
Atilda = 10*pi; %cm
V = .22; %cm/s^6
Scalar0 = 1;
t=1;
N = 1:3:5;
x = linspace(-20,20,100);
phi = zeros(length(x),length(N));
for i = 1:length(x)
for k=1:length(N)
phi(i,k) = (2*Scalar0*cos((N*pi*x)/Atilda))*(cos((N*pi*x)/Atilda))*(exp(-(V*D*((N*pi*x)/Atilda)+V*SigmaA+V*SigmaF)*t));
plot(X,phi(B))
end
end

Respuestas (1)

BhaTTa
BhaTTa el 25 de Oct. de 2024
Hey @Larry McNamara, I assume that you want to evaluate a function for "N" odd iterations from 1 to 5 and 1 to 100 with respect to x, and to plot the results, you'll need to make a below adjustments to your code:
  1. Define the Range of N: You should define N correctly for the two different cases: 1 to 5, and 1 to 100. Since you want odd iterations, you can use 1:2:5 and 1:2:99.
  2. Loop Through Each N: For each value of N, compute the function and store the results.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by