'입력 인수가 부족합니다' 이 오류를 해결하고 싶어요.

조회 수: 34 (최근 30일)
gyul
gyul 2024년 4월 10일 4:33
댓글: gyul 2024년 4월 10일 5:22
syms ('x')
xo=2000;
tolerance=0.03;
Re=1.0;
fid=fopen('solution1.txt', 'w');
while Re>tolerance
assignment2v=assignment2_2f(xo);
assignment22v=assignment2_2ff(xo);
xn=xo-assignment2v/assignment22v;
Re=abs((xn-xo)/xo);
fprintf(fid, 'approx. solution is : x=5.2%f\n', xn);
xo=xn; fo=fn; ffo=ffn;
end
fprintf(fid, 'The coverged solution is : x=5.2%f\n', xo);
type solution1.txt
----------------------------
function y=assignment2_2f(x)
y=x/400+10.245*sin(4.4934*x/4000)-2;
end
---------
function g=assignment2_2ff(x)
g=diff(assignment2_2f,x);
end
-----------------------------
assignment2_2
입력 인수가 부족합니다.
오류 발생: assignment2_2f (2번 라인)
y=x/400+10.245*sin(4.4934*x/4000)-2;
오류 발생: assignment2_2 (6번 라인)
fo=int(assignment2_2f,xo); ffo=int(assignment2_2ff,xo);
  댓글 수: 3
gyul
gyul 2024년 4월 10일 4:58
I wanted to define the substitution of 'xo' for function that 'assinment2_2f'. Now that I look at it, I don't think it's necessary. However, deleting it does not change the error.
Is the 'Re>tolerance' part correct that the one limitation you mentioned?
Dyuman Joshi
Dyuman Joshi 2024년 4월 10일 5:02
If you want to define substitution use subs instead of int.

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

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 4월 10일 5:12
I have made some changes to your code, please check the code below and refer to the comments for information -
syms('x')
%% Define the functions as symbolic functions
assignment2_2f(x) = x/400+10.245*sin(4.4934*x/4000)-2;
assignment2_2ff(x) = diff(assignment2_2f, x);
xo=2000;
%% Calculate the values with xo as inputs
%Note that you can use this syntax with symbolic functions as well
fo = assignment2_2f(xo);
ffo = assignment2_2ff(xo);
tolerance=0.03;
Re=1.0;
fid=fopen('solution1.txt', 'w');
while Re>tolerance
assignment2v=assignment2_2f(xo);
assignment22v=assignment2_2ff(xo);
xn=xo-assignment2v/assignment22v;
Re=abs((xn-xo)/xo);
%% I assume that fn and ffn are calculated based on xn
fn = assignment2_2f(xn);
ffn = assignment2_2ff(xn);
fprintf(fid, 'approx. solution is : x=5.2%f\n', xn);
xo=xn; fo=fn; ffo=ffn;
end
fprintf(fid, 'The coverged solution is : x=5.2%f\n', xo);
%% Also, you should close the file after data writing has been completed.
fclose(fid);
type solution1.txt
approx. solution is : x=5.24338.898407 approx. solution is : x=5.24629.292712 approx. solution is : x=5.24562.954523 The coverged solution is : x=5.24562.954523
  댓글 수: 1
gyul
gyul 2024년 4월 10일 5:22
ohh,,,thank you for saving me,,

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!