My code has an opstruct error. What does it mean and how to solve it?
Show older comments
clc
clear all
f = @(x, y) exp(-(x.^2 + y.^2));
x_min = 0;
x_max = 1;
y_min = @(x) 0;
y_max = @(x) -sqrt(1 - x.^2);
result = integral2(f, x_min, x_max, y_min, y_max);
fprintf('The result of the integral is:', result);
fsurf(@(x, y) exp(-(x.^2 + y.^2)), [0 1 -1 0], 'EdgeColor', 'none');
grid on;
Accepted Answer
More Answers (1)
Mr. Pavl M.
on 27 Oct 2024
Edited: Mr. Pavl M.
on 27 Oct 2024
format long
clc
clear all
f = @(x,y)exp(-(x.^2+y.^2));
x_min = 0;
x_max = 1;
y_min = 0 ;% it already matched w/o too much text
% better than later proposed @(x) zeros(size(x)), because x_min, x_max are floating point scalars;
y_max = @(x)-sqrt(1-x.^2);
result = integral2(f,x_min,x_max,y_min,y_max,'Method','auto','AbsTol',0,'RelTol',1e-12);
fprintf('The result of the integral is:');
disp(result)
fsurf(@(x,y) exp(-(x.^2+y.^2)),[0 1 0 1],'EdgeColor','green');
title('Original 1st Solution')
xlabel('x')
ylabel('y')
zlabel('f')
grid on;
Categories
Find more on Language Fundamentals 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!

