Error using input Unrecognized function or variable 't'.

조회 수: 5 (최근 30일)
Nguyen Tien Dung
Nguyen Tien Dung 2020년 6월 27일
답변: Walter Roberson 2020년 6월 27일
Hi everyone, can you help me fix this problem
***This is my matlab code
clear all
clc
prompt1='Her retirement increases by R1 % per year ';
prompt2='Plus R2 % of her yearsalary ';
prompt3='Time she started working ';
prompt4='Her salary S(t) increase exponentially after t years';
R1= input(prompt1);
R2= input(prompt2);
p= input(prompt3);
S= input(prompt4);
syms A(t)
ode = diff(A,t) -R1*A == R2*S;
cond = A(0) == 0;
ASol(t) = dsolve(ode,cond);
ASol(p)
***And when i put number and run
Her retirement increases by R1 % per year
0.06
Plus R2 % of her yearsalary
0.12
Time she started working
40
Her salary S(t) increase exponentially after t years
30*exp(t/20)
Error using input
Unrecognized function or variable 't'.
Error in untit5led (line 11)
S= input(prompt4);
Her salary S(t) increase exponentially after t years
***Thank you very much.

채택된 답변

Walter Roberson
Walter Roberson 2020년 6월 27일
S= input(prompt4);
syms A(t)
Notice you have the input(prompt4) call before you have the syms A(t) call. Because of that order, the symbolic variable t has not been defined yet, and so is not available for when the user types in 30*exp(t/20) in response to the input() prompt.
You need to move the syms line to before the S= line.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by