I know there are commands to use when finding the max values within an array, how would I do it through data from a graph?
1 view (last 30 days)
Show older comments
%%% Data Give Within Question
a = 7;
b = 3;
x = [0,b];
N = 100;
y = 0;
%%% d2f(x) = -(20+(a*f(x)))*x*(x-b);
% Choosing appropriate value for discretization step h
h = 0.01;
for n=0:N
X(n+1) = h*n;
end
% Boundary Conditions
ua = 0;
ub = 0;
% Zero the A, u and B arrays
A = zeros(N+1,N+1);
B = zeros(N+1,1);
A(1,1)=1;
A(N+1,N+1)=1;
B(1)= ua;
B(N+1)= ub;
for n=2:N
A(n,n)=-2/h^2-a*X(n)^2+a*X(n)*b; % main diagonal
A(n,n+1)=1/h^2+X(n)/(2*h); % top diagonal
A(n,n-1)=1/h^2-X(n)/(2*h); % bottom diagonal
B(n)=20*X(n)*b - 20*X(n)^2;
end
U = linsolve(A,B);
plot(X,U,'--o')
0 Comments
Answers (2)
Pratham Shah
on 28 Apr 2023
Why don't you use Min/Max function on the variable you are plotting. That will give you min/max value along with the corresponding index.
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices 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!