- #1
ineedhelpnow
- 651
- 0
I have an assignment for MATLAB where I am required to create two vectors x and y and then to find the sum in three ways.
first, create an extra variable z and find the sum
second, use the dot function
third, multiply x with the transpose of y
here's my code
here's what MATLAB gives me
using the sum of z gave the correct sum but with the other two functions for some reason its giving me 129.5077 instead of 148.2851 and i can't seem to find what i did wrong. I'd really appreciate it if someone could help me spot it out
first, create an extra variable z and find the sum
second, use the dot function
third, multiply x with the transpose of y
here's my code
Code:
x=linspace(0,1,5);
y=logspace(0,2,5);
z=x+y;
disp(x)
disp(y)
disp(sum(z))
disp(x)
disp(y)
disp(dot(x,y))
disp(x)
disp(y)
disp(x*y')
here's what MATLAB gives me
Code:
0 0.2500 0.5000 0.7500 1.0000
1.0000 3.1623 10.0000 31.6228 100.0000
148.2851
0 0.2500 0.5000 0.7500 1.0000
1.0000 3.1623 10.0000 31.6228 100.0000
129.5077
0 0.2500 0.5000 0.7500 1.0000
1.0000 3.1623 10.0000 31.6228 100.0000
129.5077
using the sum of z gave the correct sum but with the other two functions for some reason its giving me 129.5077 instead of 148.2851 and i can't seem to find what i did wrong. I'd really appreciate it if someone could help me spot it out