How do I plot a symbolic equation that I have created?
Hello everyone. I am about a month into a uni project and I am stuck on something that I cannot figure out, despite weeks of little bits of test code and Googling. I won’t share the whole thing, as it’s a project and currently about 350 lines. In general though, I have built something that solves the differential equations for an RLC circuit, showing all the working using symbolic maths.
So I get it down to the point where I have my symbol (Yt) which is equal to: val=1.0 – 0.2*exp(-1.0*t)*sin(5.0*t) – 1.0*exp(-1.0*t)*cos(5.0*t)
I have then successfully used fplot to draw this equation. However, I am now trying to demonstrate time invariance. The only way that I can find to do this is by creating a time vector, and then plotting the equation against time+1, similar to the test code below.
InputStartTime = 1
t=0:.005:5;
hold on;
test3 = -1.0*exp(-1.0*t).*cos(5.0*t)- 0.2*exp(-1.0*t).*sin(5.0*t) + 1
firstPoint = test3(1) % start point of function
plot(t+InputStartTime,test3)
plot([0 (t(1)+InputStartTime)], [0 firstPoint]) % Plot line from origin to start point of delayed function
However, and this is the key, test3 above is hardcoded. I cannot find a way of getting the sym into a format that I can use. If I try something like string, MATLAB then complains that the matrices are the "Incorrect dimensions for matrix multiplication". I then had to change the ‘*’ to ‘.*’ in the above equation. I have no idea how to take my solved equation from Symbolic maths and use it like this. Can anyone help please? This is how the formula looks once I have solved it, with yt being a "1×1 sym".
performing a string() of this gives: "1.0 – 0.2*exp(-1.0*t)*sin(5.0*t) – 1.0*exp(-1.0*t)*cos(5.0*t)" which shows that there is a * between exp() and sin/cos.Hello everyone. I am about a month into a uni project and I am stuck on something that I cannot figure out, despite weeks of little bits of test code and Googling. I won’t share the whole thing, as it’s a project and currently about 350 lines. In general though, I have built something that solves the differential equations for an RLC circuit, showing all the working using symbolic maths.
So I get it down to the point where I have my symbol (Yt) which is equal to: val=1.0 – 0.2*exp(-1.0*t)*sin(5.0*t) – 1.0*exp(-1.0*t)*cos(5.0*t)
I have then successfully used fplot to draw this equation. However, I am now trying to demonstrate time invariance. The only way that I can find to do this is by creating a time vector, and then plotting the equation against time+1, similar to the test code below.
InputStartTime = 1
t=0:.005:5;
hold on;
test3 = -1.0*exp(-1.0*t).*cos(5.0*t)- 0.2*exp(-1.0*t).*sin(5.0*t) + 1
firstPoint = test3(1) % start point of function
plot(t+InputStartTime,test3)
plot([0 (t(1)+InputStartTime)], [0 firstPoint]) % Plot line from origin to start point of delayed function
However, and this is the key, test3 above is hardcoded. I cannot find a way of getting the sym into a format that I can use. If I try something like string, MATLAB then complains that the matrices are the "Incorrect dimensions for matrix multiplication". I then had to change the ‘*’ to ‘.*’ in the above equation. I have no idea how to take my solved equation from Symbolic maths and use it like this. Can anyone help please? This is how the formula looks once I have solved it, with yt being a "1×1 sym".
performing a string() of this gives: "1.0 – 0.2*exp(-1.0*t)*sin(5.0*t) – 1.0*exp(-1.0*t)*cos(5.0*t)" which shows that there is a * between exp() and sin/cos. Hello everyone. I am about a month into a uni project and I am stuck on something that I cannot figure out, despite weeks of little bits of test code and Googling. I won’t share the whole thing, as it’s a project and currently about 350 lines. In general though, I have built something that solves the differential equations for an RLC circuit, showing all the working using symbolic maths.
So I get it down to the point where I have my symbol (Yt) which is equal to: val=1.0 – 0.2*exp(-1.0*t)*sin(5.0*t) – 1.0*exp(-1.0*t)*cos(5.0*t)
I have then successfully used fplot to draw this equation. However, I am now trying to demonstrate time invariance. The only way that I can find to do this is by creating a time vector, and then plotting the equation against time+1, similar to the test code below.
InputStartTime = 1
t=0:.005:5;
hold on;
test3 = -1.0*exp(-1.0*t).*cos(5.0*t)- 0.2*exp(-1.0*t).*sin(5.0*t) + 1
firstPoint = test3(1) % start point of function
plot(t+InputStartTime,test3)
plot([0 (t(1)+InputStartTime)], [0 firstPoint]) % Plot line from origin to start point of delayed function
However, and this is the key, test3 above is hardcoded. I cannot find a way of getting the sym into a format that I can use. If I try something like string, MATLAB then complains that the matrices are the "Incorrect dimensions for matrix multiplication". I then had to change the ‘*’ to ‘.*’ in the above equation. I have no idea how to take my solved equation from Symbolic maths and use it like this. Can anyone help please? This is how the formula looks once I have solved it, with yt being a "1×1 sym".
performing a string() of this gives: "1.0 – 0.2*exp(-1.0*t)*sin(5.0*t) – 1.0*exp(-1.0*t)*cos(5.0*t)" which shows that there is a * between exp() and sin/cos. symbolic, plot MATLAB Answers — New Questions