Evaluating a function with respect to 2 variables

7 visualizzazioni (ultimi 30 giorni)
Larry McNamara
Larry McNamara il 16 Ott 2017
Risposto: BhaTTa il 25 Ott 2024 alle 5:01
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

Risposte (1)

BhaTTa
BhaTTa il 25 Ott 2024 alle 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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by