Error using evalin

i was trying to solve a simple system of equations, when the program gives me this error: Error using evalin Undefined function or variable 'x'. Error in sym/eval (line 11) s = evalin('calle...

Error using evalin Undefined function or variable ‘x’. Error in sym/eval (line 11) s = evalin(‘ca​ller’,vect​orize(map2​mat(char(x​))));

Maria Giulia

i was trying to solve a simple system of equations, when the program gives me this error:

Error using evalin

Undefined function or variable ‘x’.

Error in sym/eval (line 11)

s = evalin(‘caller’,vectorize(map2mat(char(x))));

Error in es_6_analisi_cinematica (line 27)

xBposizioni=eval(solB.xBsol);

in fact when I go to evaluate the solutions of the system inside solB, it solves the system in x and y, rather than xBsol and yBsol. sorry that the script may seem strange but I’m Italian

i get the same problem using vpa instead of eval, the system of equations is solved with other variables, x and y

This is the script:

clear

AC=0.15;

BC=0.2;

AD=0.35;

xA=0;

yA=0;

rA=[xA yA 0];

xC=AC;

yC=0;

rC=[xC yC 0];

ii=0;

for phi=10^(-17):pi/36:2*pi

xD=AD*cos(phi);

yD=AD*sin(phi);

rD=[xD yD 0];

xBsol=sym(‘xBsol’);

yBsol=sym(‘yBsol’);

eqB1=‘xBsol*sin(phi)-yBsol*cos(phi)=0’;

eqB2=‘(xC-xBsol)^2+yBsol^2-BC^2=0’;

solB=solve(eqB1,eqB2,‘xBsol’,‘yBsol’);

xBposizioni=eval(solB.xBsol);

yBposizioni=eval(solB.yBsol);

xB1=xBposizioni(1)

yB1=yBposizioni(1)

xB2=xBposizioni(2)

yB2=yBposizioni(2)

if (phi>=0 && phi<=pi)

if yB1>=0 xB=xB1;yB=yB1;

else

xB=xB2;yB=yB2;

end

end

if (phi>pi && phi< 2*pi)

if yB1<0

xB=xB1; yB=yB1;

else

xB=xB2; yB=yB2;

end

end

rB=[xB yB 0];

figure(1)

plot([xA,xB],[yA,yB],‘k-‘,[xB, xC],[yB,yC],‘r-‘,[xA,xC],[yA,yC],‘b-‘,[xB,xD],[yB,yD],‘g-‘)

text(xA,yA,‘A’)

text(xB,yB,‘B’)

text(xC,yC,‘C’)

text(xD,yD,‘D’)

hold on

xlim([-0.5 0.5])

ylim([-0.5 0.5])

end

Accepted Answer

Stephan

Edited: Stephan

on 23 Nov 2020

clear

AC=0.15;

BC=0.2;

AD=0.35;

xA=0;

yA=0;

rA=[xA yA 0];

xC=AC;

yC=0;

rC=[xC yC 0];

syms xBsol yBsol

ii=0;

for phi=10^(-17):pi/36:2*pi

xD=AD*cos(phi);

yD=AD*sin(phi);

rD=[xD yD 0];

eqB1=xBsol*sin(phi)-yBsol*cos(phi)==0;

eqB2=(xC-xBsol)^2+yBsol^2-BC^2==0;

solB=solve(eqB1,eqB2,xBsol,yBsol);

xBposizioni=eval(solB.xBsol);

yBposizioni=eval(solB.yBsol);

xB1=xBposizioni(1);

yB1=yBposizioni(1);

xB2=xBposizioni(2);

yB2=yBposizioni(2);

if (phi>=0 && phi<=pi)

if yB1>=0

xB=xB1;

yB=yB1;

else

xB=xB2;yB=yB2;

end

end

if (phi>pi && phi< 2*pi)

if yB1<0

xB=xB1; yB=yB1;

else

xB=xB2; yB=yB2;

end

end

rB=[xB yB 0];

figure(1)

plot([xA,xB],[yA,yB],‘k-‘,[xB, xC],[yB,yC],‘r-‘,[xA,xC],[yA,yC],‘b-‘,[xB,xD],[yB,yD],‘g-‘)

text(xA,yA,‘A’)

text(xB,yB,‘B’)

text(xC,yC,‘C’)

text(xD,yD,‘D’)

hold on

xlim([-0.5 0.5])

ylim([-0.5 0.5])

end


More Answers (0)

See Also

Categories

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Error using evalin Undefined function or variable ‘x’. Error in sym/eval (line 11) s = evalin(‘ca​ller’,vect​orize(map2​mat(char(x​))));

Direct link to this question

Direct link to this question

1 Comment

Direct link to this comment

Direct link to this comment

Accepted Answer

Direct link to this answer

Direct link to this answer

0 Comments

More Answers (0)

See Also

Categories

Products

Release

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

Using eval undefined function or variable

Direct link to this question

Direct link to this question

0 Comments

Accepted Answer

Direct link to this answer

Direct link to this answer

0 Comments

More Answers (0)

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

Unrecognized function or variable

Direct link to this question

Direct link to this question

0 Comments

Answers (1)

Direct link to this answer

Direct link to this answer

2 Comments

Direct link to this comment

Direct link to this comment

Direct link to this comment

Direct link to this comment

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

Unrecognized function or variable

Direct link to this question

Direct link to this question

0 Comments

Answers (1)

Direct link to this answer

Direct link to this answer

2 Comments

Direct link to this comment

Direct link to this comment

Direct link to this comment

Direct link to this comment

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

Unrecognized function or variable ‘x’.

Direct link to this question

Direct link to this question

0 Comments

Answers (1)

Direct link to this answer

Direct link to this answer

0 Comments

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

0 / 0 / 0

Регистрация: 27.11.2016

Сообщений: 3

1

Найти экстремаль функционала

27.11.2016, 23:31. Показов 3177. Ответов 1


Прошу помощи. Необходимо найти экстремаль функционала.
В моем решении появляется три неизвестных при решении уравнения Эйлера?
Ошибка в моем понимании функции или же нужно решить систему из двух уравнений с тремя неизвестными, чтобы все работало?

Matlab M
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
clear all  % очищаем память
format long  % формат отображения чисел с 14 знаками
%disp('Решаем пример 1a')  % выводим заголовок задачи
syms x t Dx D2x   % описали символические переменные  
F=Dx.^2+x.^2+(2*x)*exp(t);  % вводим подынтегральную функцию
x0=0;  % вводим граничные условия
x1=0;
t0=0;
t1=1;
fprintf('Подынтегральная функция: F=%sn',char(F))
fprintf('Граничные условия: x(%d)=%d;   x(%d)=%dn',t0,x0,t1,x1)  
dFdx=diff(F,x)  % вычисляем Fy
dFdx1=diff(F,Dx)  % вычисляем Fy' 
d_dFdx1_dt = diff(dFdx1,t)  % (Fy')/x
d_dFdx1_dx=diff(dFdx1,x)  % (Fy')/y
d_dFdx1_dx1 = diff(dFdx1,Dx)  % (Fy')/y'=Fy'y' - условие Лежандра
dFx1dt = d_dFdx1_dt + d_dFdx1_dx*Dx + d_dFdx1_dx1*D2x  % d(Fy')/dx 
Euler = (dFdx-dFx1dt) 
%dFdx1 = simple(diff(F,Dx))  % Fy'
%dFdx1_dt=diff(dFdx1,t);
%deqEuler = [char(dFdx-dFx1dt) '=C']  % составили уравнение
 
 
%Euler = simple(dFdx-dFx1dt)   % левая часть уравнения Эйлера
deqEuler = [char(Euler ) '=C']  % составили уравнение
Sol = dsolve(deqEuler,'t')  % решаем уравнение Эйлера
if length(Sol)~=1  % решений нет или более одного
   error('Нет решений или более одного решения!');
end   
SolLeft = subs(Sol,t,sym(t0))  % подставляем x1
SolRight = subs(Sol,t,sym(t1))  % подставляем x2 
EqLeft = [char(SolLeft) '=' char(sym(x0))]  % приравняли y1
EqRight = [char(SolRight) '=' char(sym(x1))]  % приравняли y2
Con = solve(EqLeft,EqRight);  % решаем систему уравнений
C=Con.C    % присвоили полученные решения
C1=Con.C1  % символическим переменным C и C1
%C2=Con.C2  % символическим переменным C и C1
Sol1b = vpa(eval(Sol),14);  % подставляем C1, C в решение с точностью 14 знаков
fprintf('Уравнение экстремали:n%sn',char(Sol1b)) 
tpl = linspace(t0,t1);  % массив абсцисс
x0b = subs(Sol1b,t,tpl);  % вычисляем ординаты
plot ( tpl, x0b, '-r' )  % рисуем график
title ( 'bfF=Dx.^2+x.^2+(2*x)*exp(t)' )  % заголовок
xlabel('t')  % метка оси OX
ylabel('x(t)')  % метка оси OY
Leg = diff(dFdx1,Dx)  % Fy'y' - достаточное условие Лежандра
Matlab M
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Подынтегральная функция: F=Dx^2 + 2*x*exp(t) + x^2
Граничные условия: x(0)=0;   x(1)=0
 
dFdx =
 
2*x + 2*exp(t)
 
 
dFdx1 =
 
2*Dx
 
 
d_dFdx1_dt =
 
0
 
 
d_dFdx1_dx =
 
0
 
 
d_dFdx1_dx1 =
 
2
 
 
dFx1dt =
 
2*D2x
 
 
Euler =
 
2*x - 2*D2x + 2*exp(t)
 
 
deqEuler =
 
2*x - 2*D2x + 2*exp(t)=C
 
 
Sol =
 
C/4 - exp(t)/4 + exp(t)*(t/2 + (C*exp(-t))/4) + C2*exp(t) + C1*exp(-t)
 
 
SolLeft =
 
C/2 + C1 + C2 - 1/4
 
 
SolRight =
 
C/4 - exp(1)/4 + C1*exp(-1) + C2*exp(1) + exp(1)*((C*exp(-1))/4 + 1/2)
 
 
EqLeft =
 
C/2 + C1 + C2 - 1/4=0
 
 
EqRight =
 
C/4 - exp(1)/4 + C1*exp(-1) + C2*exp(1) + exp(1)*((C*exp(-1))/4 + 1/2)=0
 
Warning: Support of strings that are not valid variable names or define a number will be
removed in a future release. To create symbolic expressions, first create symbolic variables
and then use operations on them. 
> In sym>convertExpression (line 1536)
  In sym>convertChar (line 1441)
  In sym>tomupad (line 1198)
  In sym (line 177)
  In solve>getEqns (line 405)
  In solve (line 225)
  In test2 (line 34) 
Warning: Support of strings that are not valid variable names or define a number will be
removed in a future release. To create symbolic expressions, first create symbolic variables
and then use operations on them. 
> In sym>convertExpression (line 1536)
  In sym>convertChar (line 1441)
  In sym>tomupad (line 1198)
  In sym (line 177)
  In solve>getEqns (line 405)
  In solve (line 225)
  In test2 (line 34) 
Warning: Do not specify equations and variables as character strings. Instead, create symbolic
variables with syms. 
> In solve>getEqns (line 445)
  In solve (line 225)
  In test2 (line 34) 
 
C =
 
-(exp(2) - 4*C2 + 4*C2*exp(2) + 1)/(2*(exp(1) - 1))
 
 
C1 =
 
(exp(1)*(exp(1) - 4*C2 + 4*C2*exp(1) + 1))/(4*(exp(1) - 1))
 
Error using evalin
Undefined function or variable 'C2'.
 
Error in sym/eval (line 11)
s = evalin('caller',vectorize(map2mat(char(x))));
 
Error in test2 (line 38)
Sol1b = vpa(eval(Sol),14);  % подставляем C1, C в решение с точностью 14
знаков

Скажите как удалить тему с форума?

Миниатюры

Найти экстремаль функционала
 

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Понравилась статья? Поделить с друзьями:
  • Error updating the system bitrix env
  • Error updating repositories freebsd
  • Error updating changes not a git repository
  • Error updating changes detected dubious ownership
  • Error updating cell mesh in system fluid flow