Why vector don't equal when differentiating sin(pi*x)
I don't understand why i keep getting
Error using plot Vectors must be the same length
As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.
clc;
%differentiation and integration:
%Waveform of sine(pi*x):
sym('x');
s= sin(pi*x1);
x1= linspace(0,4);
subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line
matlab vector plot
add a comment |
I don't understand why i keep getting
Error using plot Vectors must be the same length
As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.
clc;
%differentiation and integration:
%Waveform of sine(pi*x):
sym('x');
s= sin(pi*x1);
x1= linspace(0,4);
subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line
matlab vector plot
5
Hi, you should read the documentation ofdiff
:If x is a vector of length m, then y=diff(x) returns a vector of length m-1
. One possible solution for your problem would be:s1=[0 s1]
– Irreducible
Nov 16 '18 at 6:31
The symbolic variablex
is never used andx1
is defined out of order. Please provide a Rundle example.
– Mad Physicist
Nov 16 '18 at 7:04
@Irreductible, this is actually the answer to the question, you should post it as an answer
– Brice
Nov 16 '18 at 8:34
add a comment |
I don't understand why i keep getting
Error using plot Vectors must be the same length
As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.
clc;
%differentiation and integration:
%Waveform of sine(pi*x):
sym('x');
s= sin(pi*x1);
x1= linspace(0,4);
subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line
matlab vector plot
I don't understand why i keep getting
Error using plot Vectors must be the same length
As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.
clc;
%differentiation and integration:
%Waveform of sine(pi*x):
sym('x');
s= sin(pi*x1);
x1= linspace(0,4);
subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line
matlab vector plot
matlab vector plot
asked Nov 16 '18 at 5:15
Anime LoverAnime Lover
32
32
5
Hi, you should read the documentation ofdiff
:If x is a vector of length m, then y=diff(x) returns a vector of length m-1
. One possible solution for your problem would be:s1=[0 s1]
– Irreducible
Nov 16 '18 at 6:31
The symbolic variablex
is never used andx1
is defined out of order. Please provide a Rundle example.
– Mad Physicist
Nov 16 '18 at 7:04
@Irreductible, this is actually the answer to the question, you should post it as an answer
– Brice
Nov 16 '18 at 8:34
add a comment |
5
Hi, you should read the documentation ofdiff
:If x is a vector of length m, then y=diff(x) returns a vector of length m-1
. One possible solution for your problem would be:s1=[0 s1]
– Irreducible
Nov 16 '18 at 6:31
The symbolic variablex
is never used andx1
is defined out of order. Please provide a Rundle example.
– Mad Physicist
Nov 16 '18 at 7:04
@Irreductible, this is actually the answer to the question, you should post it as an answer
– Brice
Nov 16 '18 at 8:34
5
5
Hi, you should read the documentation of
diff
: If x is a vector of length m, then y=diff(x) returns a vector of length m-1
. One possible solution for your problem would be: s1=[0 s1]
– Irreducible
Nov 16 '18 at 6:31
Hi, you should read the documentation of
diff
: If x is a vector of length m, then y=diff(x) returns a vector of length m-1
. One possible solution for your problem would be: s1=[0 s1]
– Irreducible
Nov 16 '18 at 6:31
The symbolic variable
x
is never used and x1
is defined out of order. Please provide a Rundle example.– Mad Physicist
Nov 16 '18 at 7:04
The symbolic variable
x
is never used and x1
is defined out of order. Please provide a Rundle example.– Mad Physicist
Nov 16 '18 at 7:04
@Irreductible, this is actually the answer to the question, you should post it as an answer
– Brice
Nov 16 '18 at 8:34
@Irreductible, this is actually the answer to the question, you should post it as an answer
– Brice
Nov 16 '18 at 8:34
add a comment |
2 Answers
2
active
oldest
votes
As mentioned in the comments
You should read the documentation of diff
:
If x is a vector of length m, then y=diff(x) returns a vector of length m-1.
One possible solution for your problem would be:
s1=[0 s1]
add a comment |
You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.
syms x;
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
sr = subs(s,x) ;
plot(x,sr);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
s1r = subs(s1,x) ;
plot(x,s1r)
YOu need not to use syms actually.
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= gradient(s);
plot(x,s1)
1
x
is never used in OP's code.
– Mad Physicist
Nov 16 '18 at 7:04
If that was the case, code would crash at the first plot attempt, not the second one
– Brice
Nov 16 '18 at 8:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331830%2fwhy-vector-dont-equal-when-differentiating-sinpix%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As mentioned in the comments
You should read the documentation of diff
:
If x is a vector of length m, then y=diff(x) returns a vector of length m-1.
One possible solution for your problem would be:
s1=[0 s1]
add a comment |
As mentioned in the comments
You should read the documentation of diff
:
If x is a vector of length m, then y=diff(x) returns a vector of length m-1.
One possible solution for your problem would be:
s1=[0 s1]
add a comment |
As mentioned in the comments
You should read the documentation of diff
:
If x is a vector of length m, then y=diff(x) returns a vector of length m-1.
One possible solution for your problem would be:
s1=[0 s1]
As mentioned in the comments
You should read the documentation of diff
:
If x is a vector of length m, then y=diff(x) returns a vector of length m-1.
One possible solution for your problem would be:
s1=[0 s1]
answered Nov 16 '18 at 11:08
IrreducibleIrreducible
668720
668720
add a comment |
add a comment |
You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.
syms x;
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
sr = subs(s,x) ;
plot(x,sr);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
s1r = subs(s1,x) ;
plot(x,s1r)
YOu need not to use syms actually.
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= gradient(s);
plot(x,s1)
1
x
is never used in OP's code.
– Mad Physicist
Nov 16 '18 at 7:04
If that was the case, code would crash at the first plot attempt, not the second one
– Brice
Nov 16 '18 at 8:33
add a comment |
You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.
syms x;
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
sr = subs(s,x) ;
plot(x,sr);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
s1r = subs(s1,x) ;
plot(x,s1r)
YOu need not to use syms actually.
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= gradient(s);
plot(x,s1)
1
x
is never used in OP's code.
– Mad Physicist
Nov 16 '18 at 7:04
If that was the case, code would crash at the first plot attempt, not the second one
– Brice
Nov 16 '18 at 8:33
add a comment |
You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.
syms x;
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
sr = subs(s,x) ;
plot(x,sr);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
s1r = subs(s1,x) ;
plot(x,s1r)
YOu need not to use syms actually.
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= gradient(s);
plot(x,s1)
You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.
syms x;
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
sr = subs(s,x) ;
plot(x,sr);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
s1r = subs(s1,x) ;
plot(x,s1r)
YOu need not to use syms actually.
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= gradient(s);
plot(x,s1)
edited Nov 16 '18 at 8:38
answered Nov 16 '18 at 7:01
Siva Srinivas KolukulaSiva Srinivas Kolukula
1,1351613
1,1351613
1
x
is never used in OP's code.
– Mad Physicist
Nov 16 '18 at 7:04
If that was the case, code would crash at the first plot attempt, not the second one
– Brice
Nov 16 '18 at 8:33
add a comment |
1
x
is never used in OP's code.
– Mad Physicist
Nov 16 '18 at 7:04
If that was the case, code would crash at the first plot attempt, not the second one
– Brice
Nov 16 '18 at 8:33
1
1
x
is never used in OP's code.– Mad Physicist
Nov 16 '18 at 7:04
x
is never used in OP's code.– Mad Physicist
Nov 16 '18 at 7:04
If that was the case, code would crash at the first plot attempt, not the second one
– Brice
Nov 16 '18 at 8:33
If that was the case, code would crash at the first plot attempt, not the second one
– Brice
Nov 16 '18 at 8:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331830%2fwhy-vector-dont-equal-when-differentiating-sinpix%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
5
Hi, you should read the documentation of
diff
:If x is a vector of length m, then y=diff(x) returns a vector of length m-1
. One possible solution for your problem would be:s1=[0 s1]
– Irreducible
Nov 16 '18 at 6:31
The symbolic variable
x
is never used andx1
is defined out of order. Please provide a Rundle example.– Mad Physicist
Nov 16 '18 at 7:04
@Irreductible, this is actually the answer to the question, you should post it as an answer
– Brice
Nov 16 '18 at 8:34