Confuse with function handles, matrix and single point
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I got homework with this a little bit complex function.
I calculate values of the function with input is a vector and single points. Same function but the results are pretty difference!!! (See on the graph.
Anyone can explain it?. Thanks a lot!
Here 's my image and code .
x =-2:.01:2;
f =@(x) x.*sqrt(x.^4+1).*log(4-x.^2)+...
6*sin(4+x.^2)/(1+exp(-x))-...
7*x;
%----------
grid on
hold on
plot(x,f(x),'*r-')
%------------------
for i=1:length(x)
plot(x(i),f(x(i)),'o')
end
%---------------------------------------------------
% ff = x.*sqrt(x.^4+1).*log(4-x.^2)+...
% 6*sin(4+x.^2)/(1+exp(-x))-...
% 7*x;
% plot(x,ff,'g')
% % -----------------------------------------
% for i=1:length(x)
% xx=x(i);
% fff = xx.*sqrt(xx.^4+1).*log(4-xx.^2)+...
% 6*sin(4+xx.^2)/(1+exp(-xx))-...
% 7*xx;
% plot(xx,fff,'y*')
% end
0 Commenti
Risposta accettata
Amit
il 12 Gen 2014
In defining f, you didn't do the function right. To take a value of x as a vector, you need to use ./ instead of just / . In think the proper code will be
x =-2:.01:2;
f =@(x) x.*sqrt(x.^4+1).*log(4-x.^2)+...
6*sin(4+x.^2) ./ (1+exp(-x))-...
7*x;
This will be same for both scaler and vector inputs.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!