Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
Eric Cheatwood
Eric Cheatwood el 23 de Oct. de 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

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by