# how to solve this error?

3 views (last 30 days)
siti nurhidayah on 24 Jan 2023
%the equation used to determine the Tfreeze == Ts- A*exp(-k*t)
%By using this equation, the time taken for ice cream to melt can be found.
clear
clc
place = menu ('Please choose place to eat the ice cream:','Outside the store','Inside the store');
switch place
case 1
%to calc the time taken for ice cream Double Choc to melt
syms A k
Tfreeze =-18; Ts= 32; t=0;
equli=Tfreeze== Ts- A*exp(-k*t);
ansk= solve(equli, A);
A1value =double (ansk);
syms k
Tfreeze=-9; Ts=32;t=1; A=A1value;
equlii =Tfreeze==Ts-A*exp(-k*t);
ansk= solve (equlii,k);
k1value =double (ansk);
syms t
Tfreeze=-13.5; Ts=32; k= k1value;
equliii=Tfreeze == Ts-A*exp(-k*t);
anst =solve (equliii,t);
t1value= double(anst);
% to calc the time taken for gelato to melt
syms A k
Tfreeze =-23; Ts=32; t=0;
equli= Tfreeze== Ts-A*exp(-k*t);
ansk= solve(equli, A);
A2value= double (ansk);
syms k
Tfreeze = -13; Ts=32; t= 1; A=A2value;
equlii=Tfreeze == Ts-A*exp(-k*t);
ansk= solve(equlii,k);
k2value = double (ansk);
syms t
Tfreeze = 15.5; Ts= 32; k=k2value;
equliii= Tfreeze == Ts-A*exp (-k*t);
anst= solve(equliii,t);
t2value=double (anst);
% to cal the time taken for frozen yogurt to melt
syms A k
Tfreeze =-20; Ts=32; t=0;
equ3i= Tfreeze == Ts- A*exp(-k*t);
ansk= solve(equ3i,A);
A3value=double(ansk);
syms k
Tfreeze= -8; Ts=32; t=1; A=A3value;
equ3ii = Tfreeze == Ts-A*exp(-k*t);
ansk=solve (equ3i,k);
k3value= double (ansk);
syms t
Tfreeze = 23.7; Ts = 25; k=k3value;
equ3iii = Tfreeze == Ts-A*exp(-k*t);
anst= solve(equ3iii,t);
t3value= double(anst);
%to calc the time taken for Sorbet to melt
syms A k
Tfreeze = -14; Ts=25; t=0;
equ4i = Tfreeze == Ts-A*exp(-k*t);
ansk=solve (equ4i,A);
A4value = double (ansk);
syms k
Tfreeze =-9; Ts= 25; t=1; A= A4value;
equ4ii = Tfreeze == Ts- A*exp(-k*t);
ansk = solve (equ4ii,k);
k4value = double (ansk);
syms t
Tfreeze = 15.7; Ts=25; k= k4value;
equ4iii = Tfreeze == Ts-A*exp(-k*t);
anst = solve (equ4iii,t);
t4value = double (anst);
%if customer want to buy the ice cream
disp ('Welcome to Anne Ice cream Shop');
%the greeting from Anne Store to customers
disp ('Menu Available Today!!: 1.Ice Cream Double Choc, 2.Gelato, 3.Frozen Yogurt and 4.Sorbet');
ice = input ('Please enter the number of ice cream')
Quantity = input ('Quantity?');
%Quantity that customers want
if Ice == 1
x=5; %Price for ice cream Double Choc
Price =x*quantity;
fprintf ('The price for %2.0f ice cream double choc is RM%4.0f\n',quantity, price);
fprintf ('The time for ice cream to melt is%3.0f minutes \n',t1value);
idsp('Enjoy your Ice Cream before it melts :');
elseif Ice == 2
x=7; %Price for Gelato
Price = x*quantity;
fprintf ('The price for %2.0f Gelato is RM%4.0f\n',quantity, Price);
fprintf('The time for Gelato melt is %3.0f minutes \n',t2value);
disp('Enjoy your gelato before it melts:)');
elseif Ice == 3
x=9; %Price for Frozen Yogurt
Price = x*quantity;
fprintf ('The price for %2.0f Frozen Yogurt melt is %3.0f minutes\n',t3value);
disp ('Enjoy your Frozen Yogurt before it melts :)');
elseif Ice == 4
x =10; %Price for Sorbet
Price =x*quantity;
fprintf ('The price for %2.0f Sorbet is RM%4.0f\n', quantity, price);
fprintf ('The time for Sorbet melt is %3.0f minutes \n',t4value);
disp('Enjoy your Sorbet before it melts :');
else
disp ('You find the ice cream you want another shop');
end
case 2
% To calc the time for Ice Cream Double Choc
syms A k
Tfreeze =-18; Ts=25 ; t=0;
equli = Tfreeze == Ts-A*exp(-k*t);
ansk = solve (equli, A);
A1value = double (ansk);
syms k
Tfreeze =-9; Ts=25; t=1; A= A1value;
equlii= Tfreeze == Ts-A*exp (-k*t);
ansk = solve (equlii, k);
k1value = double (ansk);
syms t
Tfreeze = 13.5; Ts=25; k=k1value;
equliii= Tfreeze == Ts-A*exp(-k*t);
anst = solve (equliii,t);
t1value = double(anst);
% To calc the time for Gelato
syms A k
Tfreeze =-23; Ts=25; t=0;
equli=Tfreeze ==Ts- A*exp(-k*t);
ansk = solve (equli,A);
A2value =double (ansk);
syms k
Tfreeze=-13; Ts=25; t=1; A=A2value;
equlii= Tfreeze == Ts-A*exp(-k*t);
ansk =solve (equlii,k)
k2value = double (ansk);
syms t
Tfreeze =15.5; Ts=25; k= k2value;
equliii =Tfreeze == Ts-A*exp (-k*t);
anst= solve (equliii,t);
t2value = double (anst);
%To calc the time for Frozen Yogurt
syms A k
Tfreeze =-20; Ts=25; t=0;
equ3i = Tfreeze == Ts-A*exp(-k*t);
ansk =solve (equ3i,A);
A3value = double (ansk);
syms k
Tfreeze =-8; Ts=25 ; t=1; A=A3value;
equ3ii = Tfreeze == Ts-A*exp(-k*t);
ansk = solve (equ3ii,k);
k3value= double (ansk);
syms t
Tfreeze= 23.7; Ts=25; k= k3value;
equ3iii =Tfreeze == Ts-A*exp(-k*t);
anst = solve(equ3iii,t);
t3value= double (anst);
%To calc the time taken for Sorbet
syms A k
Tfreeze = -14; Ts=25; t=0;
equ4i= Tfreeze== Ts-A*exp(-k*t);
ansk= solve(equ4i,A);
A4value = double (ansk);
syms k
Tfreeze =-9; Ts=25; t=1; A=A4value;
equ4ii =Tfreeze== Ts-A*exp(-k*t);
ansk = solve(equ4ii,k);
k4value =double (ansk);
sym t
Tfreeze =15.7; Ts=25; k=k4value;
equ4iii= Tfreeze== Ts-A*(-k*t);
anst= solve(equ4iii,t);
t4value=double (anst);
end
%if customer want to buy the ice cream
disp ('Welcome to Anne Ice cream Shop');
%the greeting from Anne Store to customers
disp ('Menu Available Today!!: 1.Ice Cream Double Choc, 2.Gelato, 3.Frozen Yogurt and 4.Sorbet');
ice = input ('Please enter the number of ice cream');
Quantity = input ('Quantity?');
%Quantity that customers want
if Ice == 1
x=5; %Price for ice cream Double Choc
Price =x*quantity;
fprintf ('The price for %2.0f ice cream double choc is RM%4.0f\n',quantity, price);
fprintf ('The time for ice cream to melt is%3.0f minutes \n',t1value);
idsp('Enjoy your Ice Cream before it melts :');
elseif Ice == 2
x=7; %Price for Gelato
Price = x*quantity;
fprintf ('The price for %2.0f Gelato is RM%4.0f\n',quantity, Price);
fprintf('The time for Gelato melt is %3.0f minutes \n',t2value);
disp('Enjoy your gelato before it melts:)');
elseif Ice == 3
x=9; %Price for Frozen Yogurt
Price = x*quantity;
fprintf ('The price for %2.0f Frozen Yogurt melt is %3.0f minutes\n',t3value);
disp ('Enjoy your Frozen Yogurt before it melts :)');
elseif Ice == 4
x =10; %Price for Sorbet
Price =x*quantity;
fprintf ('The price for %2.0f Sorbet is RM%4.0f\n', quantity, price);
fprintf ('The time for Sorbet melt is %3.0f minutes \n',t4value);
disp('Enjoy your Sorbet before it melts :');
else
disp ('You find the ice cream you want another shop');
end
Rik on 24 Jan 2023
How exactly are you attempting to run this code?
(note that flags are meant to attract the attention of site admins, not to post comments)

Sulaymon Eshkabilov on 24 Jan 2023
Here is completely fixed code. There were several errors with inconsistent variable names, setting and solving symbolic equations and misspelled MATLAB fcn names (idsp vs. disp), e.g.: ice vs. Ice, Quantity vs. quantity, etc.
%the equation used to determine the Tfreeze == Ts- A*exp(-k*t)
%By using this equation, the time taken for ice cream to melt can be found.
clear
clc
place = menu ('Please choose place to eat the ice cream:','Outside the store','Inside the store');
switch place
case 1
%to calc the time taken for ice cream Double Choc to melt
syms A k
Tfreeze =-18; Ts= 32; t=0;
equli=Tfreeze== Ts- A*exp(-k*t);
ansk= solve(equli, A);
A1value =double (ansk);
syms k
Tfreeze=-9; Ts=32;t=1; A=A1value;
equlii =Tfreeze==Ts-A*exp(-k*t);
ansk= solve (equlii,k);
k1value =double (ansk);
syms t
Tfreeze=-13.5; Ts=32; k= k1value;
equliii=Tfreeze == Ts-A*exp(-k*t);
anst =solve (equliii,t);
t1value= double(anst);
% to calc the time taken for gelato to melt
syms A k
Tfreeze =-23; Ts=32; t=0;
equli= Tfreeze== Ts-A*exp(-k*t);
ansk= solve(equli, A);
A2value= double (ansk);
syms k
Tfreeze = -13; Ts=32; t= 1; A=A2value;
equlii=Tfreeze == Ts-A*exp(-k*t);
ansk= solve(equlii,k);
k2value = double (ansk);
syms t
Tfreeze = 15.5; Ts= 32; k=k2value;
equliii= Tfreeze == Ts-A*exp (-k*t);
anst= solve(equliii,t);
t2value=double (anst);
% to cal the time taken for frozen yogurt to melt
syms A k
Tfreeze =-20; Ts=32; t=0;
equ3i= Tfreeze == Ts- A*exp(-k*t);
ansk= solve(equ3i,A);
A3value=double(ansk);
syms k
Tfreeze= -8; Ts=32; t=1; A=A3value;
equ3ii = Tfreeze == Ts-A*exp(-k*t);
ansk=solve (equ3ii,k);
k3value= double (ansk);
syms t
Tfreeze = 23.7; Ts = 25; k=k3value;
equ3iii = Tfreeze == Ts-A*exp(-k*t);
anst= solve(equ3iii,t);
t3value= double(anst);
%to calc the time taken for Sorbet to melt
syms A k
Tfreeze = -14; Ts=25; t=0;
equ4i = Tfreeze == Ts-A*exp(-k*t);
ansk=solve (equ4i,A);
A4value = double(ansk);
syms k
Tfreeze =-9; Ts= 25; t=1; A= A4value;
equ4ii = Tfreeze == Ts- A*exp(-k*t);
ansk = solve (equ4ii,k);
k4value = double(ansk);
syms t
Tfreeze = 15.7; Ts=25; k= k4value;
equ4iii = Tfreeze == Ts-A*exp(-k*t);
anst = solve (equ4iii,t);
t4value = double(anst);
%if customer want to buy the ice cream
disp ('Welcome to Anne Ice cream Shop');
%the greeting from Anne Store to customers
disp ('Menu Available Today!!: 1.Ice Cream Double Choc, 2.Gelato, 3.Frozen Yogurt and 4.Sorbet');
Ice = input ('Please enter the number of ice cream: ');
Quantity = input ('Quantity? ');
%Quantity that customers want
if Ice == 1
x=5; %Price for ice cream Double Choc
Price =x*quantity;
fprintf ('The price for %2.0f ice cream double choc is RM%4.0f\n',quantity, price);
fprintf ('The time for ice cream to melt is%3.0f minutes \n',t1value);
idsp('Enjoy your Ice Cream before it melts :');
elseif Ice == 2
x=7; %Price for Gelato
Price = x*quantity;
fprintf ('The price for %2.0f Gelato is RM%4.0f\n',quantity, Price);
fprintf('The time for Gelato melt is %3.0f minutes \n',t2value);
disp('Enjoy your gelato before it melts:)');
elseif Ice == 3
x=9; %Price for Frozen Yogurt
Price = x*quantity;
fprintf ('The price for %2.0f Frozen Yogurt melt is %3.0f minutes\n',t3value);
disp ('Enjoy your Frozen Yogurt before it melts :)');
elseif Ice == 4
x =10; %Price for Sorbet
Price =x*quantity;
fprintf ('The price for %2.0f Sorbet is RM%4.0f\n', quantity, price);
fprintf ('The time for Sorbet melt is %3.0f minutes \n',t4value);
disp('Enjoy your Sorbet before it melts :');
else
disp ('You find the ice cream you want another shop');
end
case 2
% To calc the time for Ice Cream Double Choc
syms A k
Tfreeze =-18; Ts=25 ; t=0;
equli = Tfreeze == Ts-A*exp(-k*t);
ansk = solve (equli, A);
A1value = double (ansk);
syms k
Tfreeze =-9; Ts=25; t=1; A= A1value;
equlii= Tfreeze == Ts-A*exp (-k*t);
ansk = solve (equlii, k);
k1value = double (ansk);
syms t
Tfreeze = 13.5; Ts=25; k=k1value;
equliii= Tfreeze == Ts-A*exp(-k*t);
anst = solve (equliii,t);
t1value = double(anst);
% To calc the time for Gelato
syms A k
Tfreeze =-23; Ts=25; t=0;
equli=Tfreeze ==Ts- A*exp(-k*t);
ansk = solve (equli,A);
A2value =double (ansk);
syms k
Tfreeze=-13; Ts=25; t=1; A=A2value;
equlii= Tfreeze == Ts-A*exp(-k*t);
ansk =solve (equlii,k)
k2value = double (ansk);
syms t
Tfreeze =15.5; Ts=25; k= k2value;
equliii =Tfreeze == Ts-A*exp (-k*t);
anst= solve (equliii,t);
t2value = double (anst);
%To calc the time for Frozen Yogurt
syms A k
Tfreeze =-20; Ts=25; t=0;
equ3i = Tfreeze == Ts-A*exp(-k*t);
ansk =solve (equ3i,A);
A3value = double (ansk);
syms k
Tfreeze =-8; Ts=25 ; t=1; A=A3value;
equ3ii = Tfreeze == Ts-A*exp(-k*t);
ansk = solve (equ3ii,k);
k3value= double (ansk);
syms t
Tfreeze= 23.7; Ts=25; k= k3value;
equ3iii =Tfreeze == Ts-A*exp(-k*t);
anst = solve(equ3iii,t);
t3value= double (anst);
%To calc the time taken for Sorbet
syms A k
Tfreeze = -14; Ts=25; t=0;
equ4i= Tfreeze== Ts-A*exp(-k*t);
ansk= solve(equ4i,A);
A4value = double (ansk);
syms k
Tfreeze =-9; Ts=25; t=1; A=A4value;
equ4ii =Tfreeze== Ts-A*exp(-k*t);
ansk = solve(equ4ii,k);
k4value =double (ansk);
syms t
Tfreeze =15.7; Ts=25; k=k4value; A=A4value;
equ4iii= Tfreeze== Ts-A*(-k*t);
anst= solve(equ4iii,t);
t4value=double (anst);
end
%if customer want to buy the ice cream
disp ('Welcome to Anne Ice cream Shop');
%the greeting from Anne Store to customers
disp ('Menu Available Today!!: 1.Ice Cream Double Choc, 2.Gelato, 3.Frozen Yogurt and 4.Sorbet');
Ice = input ('Please enter the number of ice cream: ');
quantity = input ('Quantity? ');
%Quantity that customers want
if Ice == 1
x=5; %Price for ice cream Double Choc
Price =x*quantity;
fprintf ('The price for %2.0f ice cream double choc is RM%4.0f\n',quantity, Price);
fprintf ('The time for ice cream to melt is%3.0f minutes \n',t1value);
disp('Enjoy your Ice Cream before it melts :');
elseif Ice == 2
x=7; %Price for Gelato
Price = x*quantity;
fprintf ('The price for %2.0f Gelato is RM%4.0f\n',quantity, Price);
fprintf('The time for Gelato melt is %3.0f minutes \n',t2value);
disp('Enjoy your gelato before it melts:)');
elseif Ice == 3
x=9; %Price for Frozen Yogurt
Price = x*quantity;
fprintf ('The price for %2.0f Frozen Yogurt melt is %3.0f minutes\n',t3value);
disp ('Enjoy your Frozen Yogurt before it melts :)');
elseif Ice == 4
x =10; %Price for Sorbet
Price =x*quantity;
fprintf ('The price for %2.0f Sorbet is RM%4.0f\n', quantity, Price);
fprintf ('The time for Sorbet melt is %3.0f minutes \n',t4value);
disp('Enjoy your Sorbet before it melts :');
else
disp ('You find the ice cream you want another shop');
end

### Categories

Find more on Programming Utilities in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!