Hi,
I have an equation for example x^2+y^2-16=0 . How can I get all of x and y value for this equation. Of course I can write it y=sqrt(16-x^2). But what if this equation is more complex. I tried something with solve command on matlab but i didn't achive. can u help me?

댓글 수: 2

Matt J
Matt J 2016년 1월 25일
How can I get all of x and y value for this equation.
There are infinite pairs x,y that solve your example equation. I think you really mean, "how can I get y for a given x?"
Cengiz Görkem DENGIZ
Cengiz Görkem DENGIZ 2016년 1월 25일
Yes i try it for x values. x=linspace (0,4,101) with solve command but it takes too much time for complex problem. Also i can plot with it ezplot. I want to get this plot data. But not from plot. First calculate data then plot.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2016년 1월 25일
편집: Matt J 2016년 1월 25일

0 개 추천

If analytical solutions exist, then SOLVE would be the thing to use.
If analytical solutions don't exist, then you would have to search numerically for a solution using FZERO or FSOLVE.

댓글 수: 6

Cengiz Görkem DENGIZ
Cengiz Görkem DENGIZ 2016년 1월 25일
Solve command take too much time. For example i want to find it for x=linspace (0,4,101). How could i calculate y values for x values easily and rapidly.
Once you have solved the equation symbolically, you could convert it to a vectorized anonymous function,
>> x=sym('x'); f=sqrt(16-x^2)
f =
(16 - x^2)^(1/2)
>> fa=str2func(['@(x)' char(vectorize(f))])
fa =
@(x)(16-x.^2).^(1./2)
>> tic;fa(linspace(0,1,401));toc
Elapsed time is 0.000538 seconds.
Seems pretty fast to me.
Cengiz Görkem DENGIZ
Cengiz Görkem DENGIZ 2016년 1월 26일
Yes you are right. But my equation is not simple like that.
s1^2/s0^2-c*s1*s2/s0/s90+s2^2/s90^2+((p+q)-(p*s1+q*s2)/sb)*s1*s2/s0/s90-su^2=0
Here s1 and s2 are variables. The others are constant.
Walter Roberson
Walter Roberson 2016년 1월 26일
So you solve() for s1 and get two results (two branches of a quadratic.) And you matlabFunction() that; do the parts individually if you need to. Then substitute in the s2 values.
Cengiz Görkem DENGIZ
Cengiz Görkem DENGIZ 2016년 1월 26일
Could you show me a little example?
c = rand; s90 = rand; p = rand; q = rand; sb = rand; su = rand; %in other words you need numeric values for them
syms s1 s2
eqn = s1^2/s0^2-c*s1*s2/s0/s90+s2^2/s90^2+((p+q)-(p*s1+q*s2)/sb)*s1*s2/s0/s90-su^2;
sols = solve(eqn, s1);
f1 = matlabFunction(sols(1), s2);
f2 = matlabFunction(sols(2), s2);
S2 = linspace(-50,50);
plot(S2, f1(S2), S2, f2(S2));

댓글을 달려면 로그인하십시오.

카테고리

질문:

2016년 1월 25일

댓글:

2016년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by