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 次查看(过去 30 天)
显示 更早的评论
%%% 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 个评论
回答(2 个)
Pratham Shah
2023-4-28
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!