Evaluating a function with respect to 2 variables

7 次查看(过去 30 天)
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

回答(1 个)

BhaTTa
BhaTTa 2024-10-25,5:01
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.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by