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)
Afficher commentaires plus anciens
The last work from which I took reference: https://www.mathworks.com/matlabcentral/answers/2049237-what-is-the-function-to-use-to-find-the-intersection-of-two-graphs?s_tid=prof_contriblnk
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:
0 commentaires
Réponse acceptée
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
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
for j = 1:length(x0)
x(j) = fsolve(fun1, x0(j));
end
x
uniquetol(x)
%% 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))
Plus de réponses (1)
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')
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!