Solve non-linear equation with varying value
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have a equation to solve
exp(-10*z)-9*exp(-2*z)+(8-4*x)=0
here
x=linspace(0,1,101)
Since the equation itself would change to a new equation for each x, i am unable to figure out how to solve it. I need to solve for z. Can somebody suggest an approach to this.
채택된 답변
madhan ravi
2019년 1월 3일
편집: madhan ravi
2019년 1월 3일
x=linspace(0,1,101);
Result=cell(1,numel(x)); % preallocate
for i = 1:numel(x)
Result{i}=fzero(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*x(i)),[0 5]);
% ^^^--initial guess interval
end
celldisp(Result)
[Result{:}] % double array
Gives:
>> [Result{:}]
ans =
Columns 1 through 7
0 0.0049 0.0096 0.0142 0.0187 0.0231 0.0274
Columns 8 through 14
0.0316 0.0357 0.0398 0.0438 0.0477 0.0517 0.0555
Columns 15 through 21
0.0594 0.0632 0.0670 0.0707 0.0744 0.0782 0.0818
Columns 22 through 28
0.0855 0.0892 0.0928 0.0964 0.1001 0.1037 0.1073
Columns 29 through 35
0.1109 0.1145 0.1181 0.1217 0.1252 0.1288 0.1324
Columns 36 through 42
0.1360 0.1396 0.1432 0.1468 0.1504 0.1540 0.1576
Columns 43 through 49
0.1612 0.1648 0.1685 0.1721 0.1758 0.1794 0.1831
Columns 50 through 56
0.1868 0.1905 0.1942 0.1979 0.2016 0.2054 0.2091
Columns 57 through 63
0.2129 0.2167 0.2205 0.2244 0.2282 0.2321 0.2359
Columns 64 through 70
0.2398 0.2438 0.2477 0.2517 0.2556 0.2596 0.2637
Columns 71 through 77
0.2677 0.2718 0.2759 0.2800 0.2842 0.2883 0.2925
Columns 78 through 84
0.2968 0.3010 0.3053 0.3096 0.3140 0.3183 0.3227
Columns 85 through 91
0.3272 0.3317 0.3362 0.3407 0.3453 0.3499 0.3545
Columns 92 through 98
0.3592 0.3640 0.3687 0.3735 0.3784 0.3833 0.3882
Columns 99 through 101
0.3932 0.3982 0.4033
>>
댓글 수: 6
P K
2019년 1월 3일
Hello Madan,Thanks for your response. But the z value should not be negative.
How you have decided that x0 =0 ? If i change x0, my answers would change. Can you explain a bit .
madhan ravi
2019년 1월 3일
편집: madhan ravi
2019년 1월 3일
Ravi Singh, x0 is the initial guess , why z shouldn't be negative ? , plot the graph to verify?
P K
2019년 1월 3일
Because I have a plot which based on the above equation. The maximum value of Z=0.4(approx) at x=1.Thats why i am saying.
madhan ravi
2019년 1월 3일
편집: madhan ravi
2019년 1월 3일
x=linspace(0,1,101);
Result=cell(1,numel(x));
for i = 1:numel(x)
Result{i}=fsolve(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*x(i)),[-5 5],optimoptions('fsolve','Display','off'));
% ^^---- change it to 0 if you only want the positive roots
end
celldisp(Result)
Note: When plotting the graph two roots were sighted , fsolve is able to find those two roots.
fplot(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*1))
% ^--- from 0 to 1 with 101 points to verify the roots
xlim([-1 1]) % to see the roots clearly
ylim([-1 1])
grid on
See the below graph the two roots can be sighted :
>> Result{end}
ans =
-0.2339 0.4033 % as you said approximately 4 (the positive root)

madhan ravi
2019년 1월 3일
편집: madhan ravi
2019년 1월 3일
@Ravi Singh, See edited answer , if you got the answer to your question make sure to accept the answer else let know of your requirements which part is not clear.
Anytime :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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
- United Kingdom (English)
