Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaire
Eric Cheatwood
Eric Cheatwood le 23 Oct 2017
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

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Oct 2017
Something like,
syms x
X = input(prompt1);
exp1 = subs(expamp2 * exp(x), x, X);
  5 commentaires
Eric Cheatwood
Eric Cheatwood le 24 Oct 2017
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 le 24 Oct 2017
Yes, it is clearer if the variable being substituted for is specified; I myself got confused when I made the above remark.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by