Can someone check whether my script is correct or not? I did this using the same method as the one last time.

2 次查看(过去 30 天)
My new work:
%%Plotting the graphs
k = @(x,y) y-3.*sin((x)^2);
fimplicit(k), grid on
hold on
m = @(x,y) y- exp(x/2) + exp(-2.*x);
fimplicit(m), grid on
hold off
xlabel('x'), ylabel('y')
legend ('y = 3 + sin(x^2)','y = e^(x/2) + e^(-2*x)','location','northeast')
When I ran the script, it showed this:

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-11-21
编辑:Dyuman Joshi 2023-11-21
There was a missing element-wise operator in the sin() in the definition of 'k'.
Also, I have modified the legend to show the expressions correctly.
% vv
k = @(x,y) y - 3.*sin((x).^2);
fimplicit(k), grid on
hold on
m = @(x,y) y - exp(x/2) + exp(-2.*x);
fimplicit(m), grid on
hold off
xlabel('x'); ylabel('y');
% v v v v
legend ('y = 3*sin(x^2)','y = e\^(x/2) - e\^(-2*x)','location','northeast')
  3 个评论
Lê
2023-11-21
I want to find the intersection points of the graphs and use them to calculate the volume of the region bounded by the graphs, but the intersection results are only 0.7722, missing the number 1.524. Any idea why?
clear;
%% Plotting the graphs
k = @(x,y) y - 3.*sin((x).^2);
fimplicit(k), grid on
hold on
m = @(x,y) y - exp(x./2) - exp((-2).*x);
fimplicit(m), grid on
hold off
xlabel('x'); ylabel('y');
legend ('y = 3*sin(x^2)','y = e\^(x/2) + e\^(-2*x)','location','northeast')
%% Finding intersection points
x0 = [-1, 1]; % initial guesses
for j = 1:2
fun1 = @(x) exp(x./2) + exp((-2).*x) - 3 .* sin((x).^2); % f(x) = g(x)
x(j) = fsolve(fun1, x0(j))
end
%% Calculating the volume
fun2 = @(x) (3.*sin(x.^2)).^2 - (exp(x./2) - exp(-2.*x)).^2;
V = pi*integral (fun2,x(1),x(2))
Walter Roberson
Walter Roberson 2023-11-21
clear;
%% Plotting the graphs
k = @(x,y) y - 3.*sin((x).^2);
fimplicit(k), grid on
hold on
m = @(x,y) y - exp(x./2) - exp((-2).*x);
fimplicit(m), grid on
hold off
xlabel('x'); ylabel('y');
legend ('y = 3*sin(x^2)','y = e\^(x/2) + e\^(-2*x)','location','northeast')
%% Finding intersection points
fun1 = @(x) exp(x./2) + exp((-2).*x) - 3 .* sin((x).^2); % f(x) = g(x)
x0 = [0 2] % initial guesses
x0 = 1×2
0 2
for j = 1:length(x0)
x(j) = fsolve(fun1, x0(j));
end
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
x
x = 1×2
0.7722 1.5242
uniquetol(x)
ans = 1×2
0.7722 1.5242
%% Calculating the volume
fun2 = @(x) (3.*sin(x.^2)).^2 - (exp(x./2) - exp(-2.*x)).^2;
V = pi*integral (fun2,x(1),x(2))
V = 9.2979

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2023-11-21
Are you sure you want and not ? You currently square x before taking sin() -- which is certainly a valid operation, but is much less common than taking the sin of x and squaring the result.
%%Plotting the graphs
k = @(x,y) y-3.*sin((x).^2);
fimplicit(k), grid on
hold on
m = @(x,y) y- exp(x/2) + exp(-2.*x);
fimplicit(m), grid on
hold off
xlabel('x'), ylabel('y')
legend ('y = 3 + sin(x^2)','y = e^(x/2) + e^(-2*x)','location','northeast')

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by