Clear Filters
Clear Filters

How to display two vectors at the same time?

9 views (last 30 days)
Philip Chen
Philip Chen on 25 Oct 2021
Commented: DGM on 25 Oct 2021
My code so far
x1=[0:1:10]
func=@(x1) 2*x1+9
x2=x1
func2=@(x2) 12-4*x2
total=[x1;func(x1)]
total2=[x2;func2(x2)]
plot(x1,func(x1))
hold on
plot(x2,func2(x2))
hold on
fprintf('(X=%5g Y=%5g)\n', total, total2)
fprintf('\n')
fprintf('(X2=%5g Y2=%5g)\n', total2)
My expected result:
(X= 0 Y= 9) (X2= 0 Y2= 12)
(X= 1 Y= 11) (X2= 1 Y2= 8)
(X= 2 Y= 13) (X2= 2 Y2= 4)
(X= 3 Y= 15) (X2= 3 Y2= 0)
(X= 4 Y= 17) (X2= 4 Y2= -4)
(X= 5 Y= 19) (X2= 5 Y2= -8)
(X= 6 Y= 21) (X2= 6 Y2= -12)
(X= 7 Y= 23) (X2= 7 Y2= -16)
(X= 8 Y= 25) (X2= 8 Y2= -20)
(X= 9 Y= 27) (X2= 9 Y2= -24)
(X= 10 Y= 29) (X2= 10 Y2= -28)
My actual result:
(X= 0 Y= 9) (X2= 1 Y2= 11)
(X= 2 Y= 13) (X2= 3 Y2= 15)
(X= 4 Y= 17) (X2= 5 Y2= 19)
(X= 6 Y= 21) (X2= 7 Y2= 23)
(X= 8 Y= 25) (X2= 9 Y2= 27)
(X= 10 Y= 29) (X2= 0 Y2= 12)
(X= 1 Y= 8) (X2= 2 Y2= 4)
(X= 3 Y= 0) (X2= 4 Y2= -4)
(X= 5 Y= -8) (X2= 6 Y2= -12)
(X= 7 Y= -16) (X2= 8 Y2= -20)
(X= 9 Y= -24) (X2= 10 Y2= -28)
What did I do wrong? How can I acheive this?
  1 Comment
DGM
DGM on 25 Oct 2021
That's not what I get when I run the same code.
x1=[0:1:10];
func=@(x1) 2*x1+9;
x2=x1;
func2=@(x2) 12-4*x2;
total=[x1;func(x1)];
total2=[x2;func2(x2)];
fprintf('(X=%5g Y=%5g)\n', total, total2)
(X= 0 Y= 9) (X= 1 Y= 11) (X= 2 Y= 13) (X= 3 Y= 15) (X= 4 Y= 17) (X= 5 Y= 19) (X= 6 Y= 21) (X= 7 Y= 23) (X= 8 Y= 25) (X= 9 Y= 27) (X= 10 Y= 29) (X= 0 Y= 12) (X= 1 Y= 8) (X= 2 Y= 4) (X= 3 Y= 0) (X= 4 Y= -4) (X= 5 Y= -8) (X= 6 Y= -12) (X= 7 Y= -16) (X= 8 Y= -20) (X= 9 Y= -24) (X= 10 Y= -28)
fprintf('\n')
fprintf('(X2=%5g Y2=%5g)\n', total2)
(X2= 0 Y2= 12) (X2= 1 Y2= 8) (X2= 2 Y2= 4) (X2= 3 Y2= 0) (X2= 4 Y2= -4) (X2= 5 Y2= -8) (X2= 6 Y2= -12) (X2= 7 Y2= -16) (X2= 8 Y2= -20) (X2= 9 Y2= -24) (X2= 10 Y2= -28)

Sign in to comment.

Answers (0)

Categories

Find more on Simulation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!