solve function answer is a 2x1 matrix . how to assign it directly to 2 variables ?

์กฐํšŒ ์ˆ˜: 7 (์ตœ๊ทผ 30์ผ)
Ruqaya
Ruqaya 2023๋…„ 11์›” 23์ผ
๋Œ“๊ธ€: Ruqaya 2023๋…„ 11์›” 23์ผ
v=[2;0;2;1;0;9;3;9;6];
m=max(v);
n=mean(v);
syms x
f=@(x) 2*n-x;
g=@(x) (n/6)*x.^2-2*m;
ezplot(f,[-10,10]);
hold on
ezplot(g,[-10,10]);
grid on
title ('graphs of f(๐‘ฅ) and g(๐‘ฅ)')
legend ('f(x)','g(x)');
s=round(solve( 2*n-x == (n/6)*x.^2-2*m ,x),5);
'x1=manually input (1st ans given by solve function above)';
'x2=manually input (2nd ans given by solve function above)';
a=int(2*n-x-(n/6)*x.^2+2*m,x1,x2);
Unrecognized function or variable 'x1'.
  ๋Œ“๊ธ€ ์ˆ˜: 2
Ruqaya
Ruqaya 2023๋…„ 11์›” 23์ผ
i need s answer to show the following : x1= "first ans" & x2= ""2nd ans""
Dyuman Joshi
Dyuman Joshi 2023๋…„ 11์›” 23์ผ
Note - The use of ezplot is not recommend. Use fplot instead.
Also, look into disp and fprintf / sprintf

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

๋‹ต๋ณ€ (1๊ฐœ)

John D'Errico
John D'Errico 2023๋…„ 11์›” 23์ผ
ํŽธ์ง‘: John D'Errico 2023๋…„ 11์›” 23์ผ
For example, I'll compute the mean of an array, which here will generate a vector of length 2.
A = rand(10,2);
mean(A,1)
ans = 1ร—2
0.4834 0.4685
Define this function handle:
splitvec = @(x) deal(x(1),x(2));
Now I can use that little toy I just built.
[xm1,xm2] = splitvec(mean(A,1))
xm1 = 0.4834
xm2 = 0.4685
It directly takes a vector of length 2, and returns 2 distinct variables. Personally, I will tell you that is a bad idea. That it is better to just return a vector, and index into it.
Of course, this works as well on symbolic results.
syms y
[y1,y2] = splitvec(solve(y^2 - 1 == 0,y))
y1ย =ย 
y2ย =ย 
1
  ๋Œ“๊ธ€ ์ˆ˜: 1
Ruqaya
Ruqaya 2023๋…„ 11์›” 23์ผ
thanks that was helpful :)

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Conversion Between Symbolic and Numeric์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by