필터 지우기
필터 지우기

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