HELP using syms to create a cosine graph
6 views (last 30 days)
Show older comments
Hello, I have some code that produced the figure in the picture but i cannot get it to work again to produce this graph. Could somebody please help me out :) Here is the code:
clear all
close all
clc
%% Data
mu0 = (4*pi)*10^(-7);
e0 = (8.854)*10^(-12);
C = 600e-9;
L = 50e-9;
R = 5e-3;
Vo = 25e3;
d = 10e-3;
%% i
%eq_1 = (Vo/ (Om*L))*exp(-(R*t)/(2*L))*sin(Om*t);
%eq_2 = (Vo/ (Om*L))*exp(-(R*t)/(2*L));
%eq_3 = (Vo/ (Om*L))*exp(-(R*t)/(2*L))*(exp(Om*t)-exp(-Om*t));
if R<2*sqrt(L/C)
disp('Use Eq_1')
else if R == 2*sqrt(L/C)
disp('Use eq_2')
else if R>2*sqrt(L/C)
disp('Use eq_3')
end
end
end
Om = sqrt((1/(L*C))-(R/(2*L))^2);
syms t
I = (Vo/(Om*L))*exp(-(R*t)/(2*L))*sin(Om*t);
Idot = diff(I)
I_graph = subs(Idot,t,(0:1e-9:1.0852e-6));
T = 0:1e-9:1.085e-6;
figure
plot(T,I_graph,'-')
grid minor
xlabel ('Time (s)')
ylabel ('Current A/s')
title('Current Time rate of change')

2 Comments
Walter Roberson
on 30 Apr 2019
Are you encountering an error message?
The code appears to work for me in R2019a.
Is it possible that you developed the code in a version of MATLAB released in the last few years, but then tried to use it in a fairly old version of MATLAB, such as before R2011b (or was it R2015a?)
Answers (1)
Walter Roberson
on 1 May 2019
You are using the Maple based Symbolic Toolbox. That has not been available from Mathworks since R2007b or so.
Perhaps you have installed Maple and permited it to install "MATLAB Connector for Maple", which is an interface that permits Maple to be called from MATLAB. That interface provides some commands such as "syms" that are the same name as the similar commands for Mathwork's Symbolic Toolbox, and that causes a conflict.
Check the output of
which -all syms
if you get a single output whose file name refers to Maple, then in that case you would only have the interface to the Maple based toolbox and would not be able to use many of the newer commands.
If you get two entries, one of which mentions Maple and the other refers to toolbox/symbolic/symbolic/syms.m then you can use pathtool to move the Maple based tools further down your MATLAB path (or remove them from you MATLAB path) so that you would get the MATLAB tools.
Maple is a good tool that I myself use most days, but to use it from MATLAB you really have to be aware of the differences between it and the Mathworks' Symbolic Toolbox.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!