Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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:

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 21 Nov 2023
Modifié(e) : Dyuman Joshi le 21 Nov 2023
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 commentaires
Lê
le 21 Nov 2023
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 le 21 Nov 2023
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

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 21 Nov 2023
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')

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by