Error using input Unrecognized function or variable 't'.

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 27 Giu 2020
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.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by