Why isn't the program run?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
clear all
clc;
syms x
f=sym(zeros(3,1));
g=sym(zeros(3,1));
h=sym(zeros(3,1));
f(1)=x;
f(2)=x^3;
f(3)=2;
g(1)=1;
g(2)=x;
g(3)=x^2;
h(1)=abs(x);
h(2)=sin(x);
h(3)=-abs(x);
ff = matlabFunction(f);
gf = matlabFunction(g);
hf = matlabFunction(h);
x = 0:0.5:10;
fgh = [ff(x)' gf(x)' hf(x)'];
figure(1)
for i = 1:3
subplot(3,1,i)
plot(x, fgh(:,i+[0 3 6]))
grid on
xlabel('x')
title( sprintf('Plot of f_{%d}, g_{%d}, h_{%d}', [i i i]))
end
4 Comments
Henric Rydén
on 9 Jun 2014
Edited: Henric Rydén
on 9 Jun 2014
Reformat your code please
Star Strider
on 9 Jun 2014
This seems to be exactly what you asked in ‘ How can i plot f(i),g(i),h(i) in one figure(i)? ’ with only the functions changing.
What did not work with that code in your changed functions?
MA
on 9 Jun 2014
MA
on 9 Jun 2014
Answers (1)
Andrei Bobrov
on 9 Jun 2014
ff = @(x)[x(:),x(:).^3,repmat(2,numel(x),1)];
gf = @(x)[ones(numel(x),1),x(:),x(:).^2];
hf = @(x)[abs(x(:)),sin(x(:)),-abs(x(:))];
x = 0:0.5:10;
fgh = [ff(x) gf(x) hf(x)];
figure(1)
for i = 1:3
subplot(3,1,i)
plot(x, fgh(:,i+[0 3 6]))
grid on
xlabel('x')
title( sprintf('Plot of f_{%d}, g_{%d}, h_{%d}', [i i i]))
end
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!