fplot in Matlab error

% I am trying to plot these three eqyations but evrytime I hit run this error shows "Error using fplot (line 149)
Invalid parameter ' ...'."
clear all;
syms V(t) a b C
time = [3.46
4.58
5.67
6.64
7.63
8.41
9.32
10.27
11.19
12.39
13.42
15.19
16.24
17.23
18.18
19.29
21.23
21.99
24.33
25.58
26.43
27.44
28.43
30.49
31.34
32.34
33
35.2
36.34
37.29
38.5
39.67
41.37
42.58
45.39
46.38
48.29
49.24
50.19
51.14
52.1
54
56.33
57.33
59.38];
Voltage = [0.0158
0.0264
0.0326
0.0445
0.0646
0.0933
0.1454
0.2183
0.2842
0.4977
0.6033
0.8441
1.2163
1.447
2.3298
2.5342
3.0064
3.4044
3.2046
4.5241
4.3459
5.1374
5.5376
4.8946
5.066
6.1494
6.8548
5.9668
6.6945
6.6395
6.8971
7.2966
7.2268
6.8815
8.0993
7.2112
7.0694
7.4971
6.9974
6.7219
7.0523
7.1095
7.0694
8.0562
7.2268];
a = 0.3389;
b = 0.0489;
sol1 = (a*tanh((a*(C+t))/2)+1)/(2*b)
a = 0.4340;
b = 0.2158;
sol2 = ((a./b).*C.*exp(a.*t))./((a./b)+C.*exp(a.*(t-1)))
syms V(t) a b C
cond = [V(0) == C]
a = 0.2375;
b = 0.1179;
eq = diff(V) == a*V-b*V*log(V);
sol3 = dsolve(eq, cond)
fplot(sol1,time,'ro')
hold on
plot(time,sol2,'B')
plot(time, sol3,'G')
hold off
legend('Data', 'Gompertz', 'Bertalanffy', 'logistic');
title(' three models')
xlabel('Time (days)');
ylabel('Voltage');

Answers (1)

Note that ‘sol1’ is a function of both ‘C’ and ‘t’. Since ‘C’ is undefined, fplot throws the error. One option is to use another function, and provide a range of values for ‘C’:
fsurf(sol1,[min(Voltage) max(Voltage) min(time) max(time)])
The arguments are taken in lexical order, so here ‘C’ is assigned ‘Voltage’ and ‘t’ is assigned ‘time’.

2 Comments

so in my equation I should replace every C with Voltage data and every t with tme data ?
like :
sol1 = @(t) ((a*tanh((a*(Voltage+time))/2)+1)/(2*b))
Also, I need the graph to be 2-D
Not necessarily.
I have no idea what your equations are modeling, so I cannot suggest an approach. I would keep them as they are (at least ‘sol1’ as a function only of time), and define ‘C’ as some numeric scalar constant before you calculate ‘sol1’. The fplot function requires that the functions it is given are functions of only one variable.
I leave that to you to decide how you want to approach that.
Also, note that:
sol1 = @(t) ((a*tanh((a*(Voltage+time))/2)+1)/(2*b))
is not actually a function of ‘t’. I would just leave it the way it is in the code you posted, and define ‘C’ as a numeric scalar.

Sign in to comment.

Tags

Asked:

on 9 Nov 2020

Commented:

on 9 Nov 2020

Community Treasure Hunt

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

Start Hunting!