How do I assign a symbolic variable only to change the variable to an array?

1 次查看(过去 30 天)
Hi, I am having a hard time trying to assign a symbolic variable to the input x. I am wanting to use x later in my code in its symbolic form but at exp1 I would like to assign the variable a value of an array. Any help is greatly appreciated.
% code
%Prompting for Amplitude and Limits of Interest
prompt = {'Enter the Value, "A", from the form A*exp(t). Include Negative Sign if Applicable',...
'Enter the Numerical Lower Limit Over Which to Plot the Function Segment'...
'Enter the Numerical Upper Limit Over Which to Plot the Function Segment'};
prompttitle = 'Information Input';
defaultans = {'1', '0', '4'};
answer = inputdlg(prompt, prompttitle, 1, defaultans);
expamp2 = str2double(answer(1,1));
explow1 = str2double(answer(2,1));
exphigh1 = str2double(answer(3,1));
%Defining Lower and Upper Limits Chosen in Each Iteration
lowerlimit1 = explow1;
upperlimit1 = exphigh1;
Syms t
%Decay Constant Prompt
prompt1 = 'Enter the Decay Constant Using the variable "/*t" and Include Positive or Negative Integers : ';
%Prompt User to input the decay constant. This was left as a
%command window input so that maximum variations can be inputted.
x = input(prompt1);
%Auto-Defining 'To' Based on Limit Selection
To = abs(exphigh1 - explow1);
Tolong = To*100;
%Defining Horizontal Axis
t = (explow1:.01:exphigh1);
%Formatting all variable to final exp form.
exp1=expamp2*exp(x);
%Generalizing naming convention for subplots
amplitude1 = exp1;
t1 = t;
clc
  1 个评论
Eric Cheatwood
Eric Cheatwood 2017-10-23
In other words, I would like exp1 to perform calculations on the array of numbers t but I would like x to hold onto the symbolic value of t to be put through a Fourier Series later on. Thanks

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-10-23
Something like,
syms x
X = input(prompt1);
exp1 = subs(expamp2 * exp(x), x, X);
  5 个评论
Eric Cheatwood
Eric Cheatwood 2017-10-24
I understand what you are saying. I defined t1 as a 'double' array. x equals some symbolic equation such as '-2*t' so the t is replaced with an array t1 using the subs function to make X but the symbolic equation x can still be used later. I suppose I could equally do the job with subs(x,t,t1) Thanks again.
Walter Roberson
Walter Roberson 2017-10-24
Yes, it is clearer if the variable being substituted for is specified; I myself got confused when I made the above remark.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by